It turns out the code has the following form:
#Override
public void onBindViewHolder(DataAdapter.ViewHolder holder, int position) {
final Phone phone = phones.get(position);
holder.imageView.setImageResource(phone.getImage());
holder.nameView.setText(phone.getName());
holder.companyView.setText(phone.getCompany());
holder.button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.e("click: ", phone.getClickbutton());
startActivity(new Intent(this, Information.class));
}
});
}
Respectively:
startActivity(new Intent(this, Information.class));
She doesn’t want to work here.
I give the full adapter code:
public class DataAdapter extends RecyclerView.Adapter<DataAdapter.ViewHolder> {
private LayoutInflater inflater;
private List<Phone> phones;
public DataAdapter(Context context, List<Phone> phones) {
this.phones = phones;
this.inflater = LayoutInflater.from(context);
}
#Override
public DataAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.list_item, parent, false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(DataAdapter.ViewHolder holder, int position) {
final Phone phone = phones.get(position);
holder.imageView.setImageResource(phone.getImage());
holder.nameView.setText(phone.getName());
holder.companyView.setText(phone.getCompany());
holder.button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.e("click: ", phone.getClickbutton());
startActivity(new Intent(this, Information.class));
}
});
}
#Override
public int getItemCount() {
return phones.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
final ImageView imageView;
final TextView nameView, companyView;
final Button button;
ViewHolder(View view){
super(view);
imageView = (ImageView)view.findViewById(R.id.image);
nameView = (TextView) view.findViewById(R.id.name);
companyView = (TextView) view.findViewById(R.id.company);
button = (Button) view.findViewById(R.id.button);
}
}
}
List item
That is the actual question. How can I open a new activity from the adapter ... Thank you.
Don't dispose passed context to your adapter
public class DataAdapter extends RecyclerView.Adapter<DataAdapter.ViewHolder> {
private LayoutInflater inflater;
private List<Phone> phones;
private Context context;
public DataAdapter(Context context, List<Phone> phones) {
this.context = context;
this.phones = phones;
this.inflater = LayoutInflater.from(context);
}
// Remainder code
}
Then use context to start new activity
#Override
public void onBindViewHolder(DataAdapter.ViewHolder holder, int position) {
final Phone phone = phones.get(position);
holder.imageView.setImageResource(phone.getImage());
holder.nameView.setText(phone.getName());
holder.companyView.setText(phone.getCompany());
holder.button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.e("click: ", phone.getClickbutton());
context.startActivity(new Intent(this, Information.class));
}
});
}
Related
I have an adapter class Where i Want to show a BLOCK USER dialog on particular position.
for example if i want to block position 1 of recyclerView .
So can any one help me porgrammatically?
Given below is the Code Of adapter Please check
I want to block user profile based on Recycler View position
if someone could help me in it please;
public class TableProfileAdapter extends RecyclerView.Adapter<TableProfileAdapter.MyViewHolder> {
Context context;
Activity getActivity;
List<TableProfile> profileUser;
OnRecItemClick onRecItemClick;
private boolean isScaleAnimationDone = false;
private boolean isTimerTextViewActionUpCalled = false;
public TableProfileAdapter(List<TableProfile> profileUser, Context context) {
this.profileUser = profileUser;
this.context = context;
}
#NonNull
#Override
public MyViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.profile_item, parent, false);
return new MyViewHolder(view, onRecItemClick);
}
#Override
public void onBindViewHolder(#NonNull MyViewHolder holder, int position) {
TableProfile data = profileUser.get(position);
holder.tvUserName.setText(data.getProfileName());
Bitmap image = BitmapManager.byteToBitmap(data.getProfileImage());
holder.profilePic.setImageBitmap(image);
if (context instanceof AccessProfileManagementActivity) {
context.startActivity(new Intent(context,HomeActivity.class));
} else if (context instanceof ProfileManagement) {
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(context, ProfileDetailsActivity.class);
TableProfile model = profileUser.get(holder.getAdapterPosition());
intent.putExtra("DATA", model);
context.startActivity(intent);
notifyDataSetChanged();
((Activity) context).finish();
}
});
}
}
#Override
public int getItemCount() {
return profileUser.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
CircleImageView profilePic;
TextView tvUserName, birthday;
OnRecItemClick onRecItemClick;
RelativeLayout relativeLayout;
public MyViewHolder(#NonNull View itemView, OnRecItemClick onRecItemClick) {
super(itemView);
profilePic = itemView.findViewById(R.id.profileImage);
tvUserName = itemView.findViewById(R.id.userName);
relativeLayout = itemView.findViewById(R.id.relTop);
this.onRecItemClick = onRecItemClick;
itemView.setOnClickListener(this);
}
#Override
public void onClick(View view) {
onRecItemClick.onItemClick(getAdapterPosition());
}
}
public interface OnRecItemClick {
void onItemClick(int position);
}
}
I made a recycler view inside the recycler view. And when I select the inside recycler view, the dialog is displayed, and I want to configure the recycler view in that dialog. I made a dialog and succeeded in displaying the dialog. but I don't know how to make a recycler view in a dialog. please help me.
Dialog class
public class RoomDialog extends Dialog {
private EditText etStudentName, etStudentNumber;
private Button btnConfirm, btnCancel;
private Context context;
private CustomDialogClickListener clickListener;
private Retrofit retrofit;
public EditText getEtStudentName() {
return etStudentName;
}
public EditText getEtStudentNumber() {
return etStudentNumber;
}
public Button getBtnConfirm() {
return btnConfirm;
}
public Button getBtnCancel() {
return btnCancel;
}
public RoomDialog(#NonNull Context context) {
super(context);
this.context = context;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_room);
etStudentName = findViewById(R.id.et_room_Studentname);
etStudentNumber = findViewById(R.id.et_room_studentNumber);
btnConfirm = findViewById(R.id.btn_room_confrim);
btnCancel = findViewById(R.id.btn_room_cancel);
btnConfirm.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dismiss();
}
}) ;
btnCancel.setOnClickListener( new View.OnClickListener(){
#Override
public void onClick(View v) {
dismiss();
}
});
}
}
Inner recycler view
public class RoomAdapter extends RecyclerView.Adapter<RoomAdapter.CustomViewHolder> {
private Context context;
private ArrayList<RoomData> rooms;
public ArrayList<StudnetInRoomData> students;
private LayoutInflater inflater;
public RoomAdapter(Context context, ArrayList<RoomData> rooms) {
this.context = context;
this.rooms = rooms;
this.inflater = LayoutInflater.from(context);
students = new ArrayList<>();
}
#Override
public CustomViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view;
view = inflater.inflate(R.layout.single_room, parent, false);
return new CustomViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull CustomViewHolder holder, int position) {
RoomData room = rooms.get(position);
holder.tvRoomNum.setText(String.valueOf(room.roomNum));
}
#Override
public int getItemCount() {
return rooms.size();
}
public class CustomViewHolder extends RecyclerView.ViewHolder {
public TextView tvRoomNum;
public TextView tvRoomTitle;
public CustomViewHolder(View itemView) {
super(itemView);
tvRoomNum = (TextView) itemView.findViewById(R.id.tvRoomNumber);
tvRoomTitle = (TextView) itemView.findViewById(R.id.tv_room_title);
tvRoomNum.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view) {
RoomDialog roomDialog = new RoomDialog(context);
roomDialog.setCanceledOnTouchOutside(true);
roomDialog.setCancelable(true);
roomDialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
roomDialog.show();
}
});
}
}
}
How can i fix twice data error.
After scrolling inside the RecyclerView, I am having a issue which is twice data.
Here is my Activity:
apiInterface = ApiClient.getApiClient().create(ApiInterface.class);
Call<List<Contacts>> call = apiInterface.chat(getUserLogin,friendId);
call.enqueue(new Callback<List<Contacts>>() {
#Override
public void onResponse(Call<List<Contacts>> call, Response<List<Contacts>> response) {
contacts = response.body();
CustomAdapterOfChat adapter = new CustomAdapterOfChat(contacts, ChatActivity.this);
recyclerView.setAdapter(adapter);
size = String.valueOf(contacts.size());
}
#Override
public void onFailure(Call<List<Contacts>> call, Throwable t) {
Toast.makeText(getApplicationContext(), "Error\n"+t.toString(), Toast.LENGTH_LONG).show();
}
});
My customAdapter ViewHolder
public class CustomAdapterOfChat extends RecyclerView.Adapter<CustomAdapterOfChat.MyViewHolder> {
private List<Contacts> contacts;
private Context context;
String getUserLogin;
public CustomAdapterOfChat(List<Contacts> contacts, Context context) {
this.contacts = contacts;
this.context = context;
}
#Override
public CustomAdapterOfChat.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.items_of_chat, parent, false);
return new CustomAdapterOfChat.MyViewHolder(view);
}
#Override
public void onBindViewHolder(CustomAdapterOfChat.MyViewHolder holder, final int position) {
//Fetching id from shared preferences
SharedPreferences sharedPreferences;
sharedPreferences =context.getSharedPreferences(Constant.SHARED_PREF_NAME, Context.MODE_PRIVATE);
getUserLogin = sharedPreferences.getString(Constant.ID_SHARED_PREF, "");
Log.d("USER_ID",getUserLogin);
Log.d("FRIEND_ID",contacts.get(position).getFriendId());
holder.time.setText(contacts.get(position).getDateAndTime());
if(getUserLogin.equals(contacts.get(position).getFriendId())) {
holder.msg_of_me.setVisibility(View.INVISIBLE);
holder.msg_of_them.setText(contacts.get(position).getMessage());
holder.img.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context, UserProfileActivity.class);
intent.putExtra("id",contacts.get(position).getFriendId());
context.startActivity(intent);
}
});
Glide.with(context)
.load(Constant.BASE_URL+"y_chat/sign_up/"+contacts.get(position).getFriendName()+"/profile.png")
.error(R.drawable.error)
.into(holder.img);
}else{
holder.img.setVisibility(View.INVISIBLE);
holder.msg_of_them.setVisibility(View.INVISIBLE);
holder.msg_of_me.setText(contacts.get(position).getMessage());
}
}
#Override
public int getItemCount() {
return contacts.size();
}
public static class MyViewHolder extends RecyclerView.ViewHolder{
TextView msg_of_me,msg_of_them,time;
ImageView img;
public MyViewHolder(View itemView) {
super(itemView);
msg_of_me = itemView.findViewById(R.id.message_text1);
msg_of_them = itemView.findViewById(R.id.message_text);
img = itemView.findViewById(R.id.img_of_them);
time = itemView.findViewById(R.id.message_time);
}
}
}
You are getting data from SharedPreferences which is time consuming task however you can edit your code this way and check the output.
public class CustomAdapterOfChat extends RecyclerView.Adapter {
private List<Contacts> contacts;
private Context context;
String getUserLogin;
public CustomAdapterOfChat(List<Contacts> contacts, Context context) {
this.contacts = contacts;
this.context = context;
//get user Id here.
SharedPreferences sharedPreferences;
sharedPreferences =context.getSharedPreferences(Constant.SHARED_PREF_NAME,
Context.MODE_PRIVATE);
getUserLogin = sharedPreferences.getString(Constant.ID_SHARED_PREF, "");
}
#Override
public CustomAdapterOfChat.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.items_of_chat, parent, false);
return new CustomAdapterOfChat.MyViewHolder(view);
}
#Override
public void onBindViewHolder(CustomAdapterOfChat.MyViewHolder holder, final int position) {
Log.d("USER_ID",getUserLogin);
Log.d("FRIEND_ID",contacts.get(position).getFriendId());
holder.time.setText(contacts.get(position).getDateAndTime());
if(getUserLogin.equals(contacts.get(position).getFriendId())) {
holder.msg_of_me.setVisibility(View.INVISIBLE);
holder.msg_of_them.setText(contacts.get(position).getMessage());
holder.img.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context, UserProfileActivity.class);
intent.putExtra("id",contacts.get(position).getFriendId());
context.startActivity(intent);
}
});
Glide.with(context)
.load(Constant.BASE_URL+"y_chat/sign_up/"+contacts.get(position).getFriendName()+"/profile.png")
.error(R.drawable.error)
.into(holder.img);
}else{
holder.img.setVisibility(View.INVISIBLE);
holder.msg_of_them.setVisibility(View.INVISIBLE);
holder.msg_of_me.setText(contacts.get(position).getMessage());
}
}
#Override
public int getItemCount() {
return contacts.size();
}
public static class MyViewHolder extends RecyclerView.ViewHolder{
TextView msg_of_me,msg_of_them,time;
ImageView img;
public MyViewHolder(View itemView) {
super(itemView);
msg_of_me = itemView.findViewById(R.id.message_text1);
msg_of_them = itemView.findViewById(R.id.message_text);
img = itemView.findViewById(R.id.img_of_them);
time = itemView.findViewById(R.id.message_time);
}
}
I'm using Horizontal Recycleview to show the icon in my app. It cotains one Recycle view and one Mainactivity Class.
I'm trying to use the onClick listener method inside the adapter class but to my surprise it is not working yet all and also don't recognize intent and give cannot resolve intent symbol. so I used toast message instead but also app compile sucessfully but nothing happens.
Here is my Recycle view class
public class SnapRecyclerAdapter extends RecyclerView.Adapter<SnapRecyclerAdapter.ReyclerViewHolder> {
private LayoutInflater layoutInflater;
private Context context;
private ArrayList<Item> items;
public SnapRecyclerAdapter(Context context, ArrayList<Item> items) {
this.layoutInflater = LayoutInflater.from(context);
this.context = context;
this.items = items;
}
#Override
public ReyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View item = layoutInflater.inflate(R.layout.item_recycler_view, parent, false);
return new ReyclerViewHolder(item);
}
#Override
public void onBindViewHolder(final ReyclerViewHolder holder, int position) {
Item item = items.get(position);
holder.image.setImageResource(item.getDrawable());
holder.appName.setText(item.getName());
}
#Override
public int getItemCount() {
return items.size();
}
class ReyclerViewHolder extends RecyclerView.ViewHolder {
private ImageView image;
private TextView appName;
private ReyclerViewHolder(final View v) {
super(v);
image = (ImageView) v.findViewById(R.id.image);
appName = (TextView) v.findViewById(R.id.app_name);
context = v.getContext();
}
private View.OnClickListener Click=new View.OnClickListener(){
#Override
public void onClick(View v) {
switch(getAdapterPosition())
{
case 1:
Toast.makeText(context, "No data available", Toast.LENGTH_SHORT).show();
}
}
};
}
}
and my Mainactivity class is
public class MainActivity extends AppCompatActivity {
private ArrayList<Item> items;
private RecyclerView recyclerView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
createApps();
SnapHelper snapHelper = new GravitySnapHelper(Gravity.BOTTOM);
snapHelper.attachToRecyclerView(recyclerView);
// HORIZONTAL for Gravity START/END and VERTICAL for TOP/BOTTOM
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
recyclerView.setHasFixedSize(true);
SnapRecyclerAdapter adapter = new SnapRecyclerAdapter(this, items);
recyclerView.setAdapter(adapter);
}
private void createApps() {
items = new ArrayList<>();
items.add(new Item("Google+", R.drawable.google_plus));
items.add(new Item("Facebook", R.drawable.facebook));
items.add(new Item("LinkedIn", R.drawable.linkedin));
items.add(new Item("Youtube", R.drawable.youtube));
items.add(new Item("Instagram", R.drawable.instagram));
items.add(new Item("Skype", R.drawable.skype));
items.add(new Item("Twitter", R.drawable.twitter));
items.add(new Item("Wikipedia", R.drawable.wikipedia));
items.add(new Item("Whats app", R.drawable.what_apps));
items.add(new Item("Pokemon Go", R.drawable.pokemon_go));
}
}
Your implementation setOnClickListener is not correct. You should set it for each view in RecylerView and inside that you can write your code to start an activity or show a toast, etc.
public class SnapRecyclerAdapter extends RecyclerView.Adapter<SnapRecyclerAdapter.ReyclerViewHolder> {
private LayoutInflater layoutInflater;
private Context context;
private ArrayList<Item> items;
public SnapRecyclerAdapter(Context context, ArrayList<Item> items) {
this.layoutInflater = LayoutInflater.from(context);
this.context = context;
this.items = items;
}
#Override
public ReyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View item = layoutInflater.inflate(R.layout.item_recycler_view, parent, false);
ReyclerViewHolder holder = new ReyclerViewHolder(item)
item.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(context, items.get(holder.getAdapterPosition()).getName(), Toast.LENGTH_SHORT).show();
// TODO: You can start an activity by using Intent as well.
}
});
return holder;
}
#Override
public void onBindViewHolder(final ReyclerViewHolder holder, int position) {
Item item = items.get(position);
holder.image.setImageResource(item.getDrawable());
holder.appName.setText(item.getName());
}
#Override
public int getItemCount() {
return items.size();
}
class ReyclerViewHolder extends RecyclerView.ViewHolder {
private ImageView image;
private TextView appName;
private ReyclerViewHolder(final View v) {
super(v);
image = (ImageView) v.findViewById(R.id.image);
appName = (TextView) v.findViewById(R.id.app_name);
context = v.getContext();
}
}
}
You want the click listener on the whole itemView? Here is an example:
//Implement View.OnClickListener
class ReyclerViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private ImageView image;
private TextView appName;
private ReyclerViewHolder(final View v) {
super(v);
image = (ImageView) v.findViewById(R.id.image);
appName = (TextView) v.findViewById(R.id.app_name);
// Set the onClickListener
v.setOnClickListener(this)
}
#Override
public void onClick(View v) {
// if (getAdapterPosition() != RecyclerView.NO_POSITION) {
Context context = v.getContext();
Intent intent = new Intent(context, aActivityClass.class);
intent.putExtra(extraKey, extraValue);
context.startActivity(intent)
// }
};
}
Do you set the click listener on a View ? Something like image.setOnClickListener(Click) ? By the way, variables should start with lowercase
you need to pass the view from adapter by using onclickListner and make and internface in adapter
this is where we are passing the view in adapter :
#Override
public void onBindViewHolder(myholder holder, final int position) {
holder.parent.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
onItemClick.click(position,view);
}
});
Interface for adapter onclick and activity:
public void clickItem(PartnerBankAdapter.OnItemClick onItemClick){
this.onItemClick=onItemClick;
}
public interface OnItemClick{
public void click(int postion,View view);
}
Define Interface as glocbal object in adapter:
private OnItemClick onItemClick;
Consider this example for adapter:
public class PartnerBankAdapter extends RecyclerView.Adapter<PartnerBankAdapter.myholder> {
public Context mContext;
ArrayList<String> bankname;
ArrayList<Integer> iconlist;
private OnItemClick onItemClick;
public PartnerBankAdapter(Context mContext, ArrayList<String> banklist,ArrayList<Integer> iconlist)
{
this.mContext = mContext;
this.bankname=banklist;
this.iconlist=iconlist;
}
#Override
public myholder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.bank_list_adpater,parent,false);
return new myholder(view);
}
#Override
public void onBindViewHolder(myholder holder, final int position) {
holder.parent.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
onItemClick.click(position,view);
}
});
holder.txt.setText(bankname.get(position));
holder.image.setImageResource(iconlist.get(position));
holder.txtacc.setText(bankname.get(position));
}
#Override
public int getItemCount() {
return bankname.size();
}
public static class myholder extends RecyclerView.ViewHolder {
TextView txt,txtacc;
ImageView image;
LinearLayout parent;
public myholder(View itemView) {
super(itemView);
txt= (TextView) itemView.findViewById(R.id.txbank);
image=(ImageView) itemView.findViewById(R.id.imagebank);
parent=(LinearLayout) itemView.findViewById(R.id.parent);
txtacc=(TextView) itemView.findViewById(R.id.txbankacc);
}
}
public void clickItem(PartnerBankAdapter.OnItemClick onItemClick){
this.onItemClick=onItemClick;
}
public interface OnItemClick{
public void click(int postion,View view);
}
}
and then just use onclick in your activity on recyclerview
consider code below for onclick in activity :
partnerBankAdapter.clickItem(new PartnerBankAdapter.OnItemClick() {
#Override
public void click(int postion, View view) {
}
});
I want to pass a string value from my adapter class to my fragment. I tried storing the string in a bundle. To retrieve the value i used Bundle b = getArguments(); b.getString("key") the problem is im getting a null pointer exception. Below is the code that saves the string in a bundle. So my question is how can i pass a string value from adapterA to fragmentB.
Thanks in advance.
Adapter.java
public class ToDoRecyclerViewAdapter extends RecyclerView.Adapter<ToDoRecyclerViewAdapter.ViewHolder> {
private Context context;
private List<Aktivnost_> mValues;
private final OnListFragmentInteractionListener mListener;
public ToDoRecyclerViewAdapter td;
public ToDoRecyclerViewAdapter(List<Aktivnost_ > items, Context context, OnListFragmentInteractionListener listener) {
mValues = items;
mListener = listener;
this.context = context;
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.fragment_todo, parent, false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
holder.mItem = mValues.get(position);
holder.mContentView.setText(mValues.get(position).getNaziv());
holder.mDateView.setText(mValues.get(position).getDatum());
holder.mView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (null != mListener) {
mListener.onListFragmentInteraction(holder.mItem);
Intent i = new Intent(context.getApplicationContext(), PodrobnostiActivity.class);
i.putExtra("task_id", mValues.get(position).getId_());
context.getApplicationContext().startActivity(i);
Toast.makeText(v.getContext(), "task - " + mValues.get(position).getId_(), Toast.LENGTH_SHORT).show();
}
}
});
holder.mView.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(final View v) {
AlertDialog.Builder adb = new AlertDialog.Builder(v.getContext());
CharSequence meni[] = new CharSequence[] {"DOING", "FINISHED"};
adb.setItems(meni, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
if(i == 0) {
Bundle b = new Bundle();
DoingFragment d = new DoingFragment();
mValues.get(i).setStanje("doing");
b.putString("doing", mValues.get(i).getStanje());
d.setArguments(b);
} else {
mValues.get(i).setStanje("koncano");
}
}
});
AlertDialog alertDialog = adb.create();
alertDialog.setCancelable(true);
alertDialog.show();
return true;
}
});
}
#Override
public int getItemCount() {
return mValues.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public final View mView;
public final TextView mContentView;
public final TextView mDateView;
public long id;
public Aktivnost_ mItem;
public ViewHolder(View view) {
super(view);
mView = view;
this.id = id;
mDateView = (TextView) view.findViewById(R.id.Date);
mContentView = (TextView) view.findViewById(R.id.content);
}
#Override
public String toString() {
return super.toString() + " '" + mContentView.getText() + "'";
}
}
}
And i want to get the value i set in bundle in this fragment.
Fragment.java
public class DoingFragment extends Fragment {
DoingFragmentRecyclerViewAdapter mAdapter;
private OnListFragmentInteractionListener mListener;
public DoingFragment() {
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_doingfragment_list, container, false);
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.list_doing);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), LinearLayoutManager.VERTICAL));
mAdapter = new DoingFragmentRecyclerViewAdapter(listAktivnosti(),mListener);
recyclerView.setAdapter(mAdapter);
return view;
}
#Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnListFragmentInteractionListener) {
mListener = (OnListFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnListFragmentInteractionListener");
}
}
#Override
public void onDetach() {
super.onDetach();
mListener = null;
}
public interface OnListFragmentInteractionListener {
void onListFragmentInteraction1(Aktivnost_ item);
}
AppDatabase db;
public void openDB() {
db = new AppDatabase(getContext());
db.open();
}
Aktivnost_ ak;
List<Aktivnost_> array;
public List<Aktivnost_> listAktivnosti() {
array = new ArrayList<>();
openDB();
Bundle b = getArguments();
Cursor cursor = db.getAllRows(b.getString("doing"));
while(cursor.moveToNext()) {
ak = new Aktivnost_();
ak.setId_(cursor.getLong(cursor.getColumnIndex("_id")));
ak.setNaziv(cursor.getString(cursor.getColumnIndex("naziv")));
ak.setDatum(cursor.getString(cursor.getColumnIndex("datum")));
ak.setFk_projekt(cursor.getInt(cursor.getColumnIndex("fk_projekt")));
ak.setUdeleženci(cursor.getString(cursor.getColumnIndex("udelezenci")));
ak.setStanje(cursor.getString(cursor.getColumnIndex("stanje")));
array.add(ak);
}
return array;
}
}
From the code, I can see you are only setting the Bundle parameters in Fragment object, but not using that fragment object further.
You need to display that fragment object first, then it will reflect into your target fragment.