Listview Item Onclick Fragment
Good Day, I'm making a listview item onClick in fragment. Every time I click the other item it shows the same fragment activity. What should I do to to make it different from the o
Solution 1:
you could use position
variable
lv.setOnItemClickListener(newAdapterView.OnItemClickListener() {
@OverridepublicvoidonItemClick(AdapterView<?> parent, View view,
int position, long id) {
if(position == 0){
TW1fragment=newTW1();
FragmentTransactiontransaction= getFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, fragment);
transaction.addToBackStack(null);
transaction.commit();
}
elseif(){
}
//// or even switchswitch(position){
case1:
// do your workbreak;
}
}
});
Solution 2:
If you want identify position click you can use Case over here in itemclickListener. Or you can set position with fragment using bundle and then identify clicked position in Fragment as well.
lv.setOnItemClickListener(newAdapterView.OnItemClickListener() {
@OverridepublicvoidonItemClick(AdapterView<?> parent, View view,
int position, long id) {
Bundlebundle=newBundle();
bundle.putString("position", position);
TW1fragment=newTW1();
fragment.setArgument(bundle);
FragmentTransactiontransaction= getFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, fragment);
transaction.addToBackStack(null);
transaction.commit();
}
});
Post a Comment for "Listview Item Onclick Fragment"