How To Implement Two Onclicklisteners On Recyclerview Item Click?
I'm quite confused since I need to use two OnClickListeners for two different needs. I have a Recyclerview which once any item of his, once pressed, needs to change and I've implem
Solution 1:
Remove below code from RecyclerView.ViewHolder
@OverridepublicvoidonClick(View v) {
listener.onItemClick(v, getAdapterPosition());
}
And add listner event in "itemView" click as below:
((SelectedProjectItemHolder) holder).itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(listener != null){
listener.onItemClick(v, getAdapterPosition());
}
dataSet.remove(listPosition);
dataSet.add(listPosition, unselectedCards.get(listPosition));
notifyItemChanged(listPosition);
}
});
Solution 2:
You can change your BottomBar width same (unique) click using UIHandler or MainLoop,with which you can access the UI from your adapter. on your OnCreate:
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
//.....HandleruiHandle=newHandler(getMainLooper()){
@OverridepublicvoidhandleMessage(Message msg) {
super.handleMessage(msg);
Bundleb= (Bundle) msg.obj;
intp= b.getInt("position");
Toast.makeText(MainActivity.this, "Change here your BottomBAR", Toast.LENGTH_SHORT).show();
}
};
.. and in your adapter ...
yourobjectclick.setOnClickListener(newView.OnClickListener() {
@OverridepublicvoidonClick(View v) {
// example: first change color of my object that I have clicked
((TextView)v).setTextColor( mContext.getResources().getColor(R.color.blue_100));
Bundlebundle=newBundle();
//i can store the position about click and
bundle.putInt("position",position);
Messagemessage= handler.obtainMessage();
message.obj = bundle;
// i have access tu User Interface objects from here// next change my bottombar sending a message to UI
handler.sendMessage(message);
Toast.makeText(mContext, "onClick: su -> "+tvBikeName.getText(), Toast.LENGTH_SHORT).show();
}
});
Post a Comment for "How To Implement Two Onclicklisteners On Recyclerview Item Click?"