Listview Itemclick Not Work

Click is not working on the Listitem Listview android

The first thing what you have to note here is, whenever there are Clickable elements like Buttons or ImageButtons present in your ListView element, they take the control of click events. And so your ListView won't get the chance to accept the click event.

What you simply have to do is, set the focusable attribute to false for the Button or ImageButton you have in your ListView. But still they will work without any problem and also your ListView's onListItemClick will also work.

Try this,

        <Button  android:id="@+id/textsize_increaser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/back_button"
android:focusable="false"
android:text=" A + "/>

Here I have added this android:focusable="false" and it works fine. try it.

UWP: ListView ItemClick not work

For click event to work, IsItemClickEnabled="True" should be added to the ListView.

Android: ListView item click not working properly

What I think is your problem with getting the wrong data is that you're getting the data based on the item clicked from a different data set then what the adapter is basing its view on (the two data sets may contain the same data but in differing orders).

Here you're are building your data set from json:

 //for each where we get back values from sting set, then convert to product 
for (String id : myJson) {
StackProduits savedProduct = gson.fromJson(id, StackProduits.class);
listProduits.add(savedProduct);
}
adapterFavoris = new ProduitsAdapter(getApplicationContext(), -1, listProduits);
produitFavorisListView.setAdapter(adapterFavoris);

Here inside of your OnItemClickListener, based on your method signature you're retrieving the data from a file:

 //Set the click listener to launch the browser when a row is clicked. 
produitFavorisListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int pos, long id) {
Intent intentProduitFavorisDetail = new Intent(Favoris.this, ProduitDetail.class);
StackProduits ProduitFavoris = ProduitsXmlPullParser.getStackProduitFromFile(Favoris.this).get(pos);
intentProduitFavorisDetail.putExtra("produit", ProduitFavoris);
startActivity(intentProduitFavorisDetail);
}
});

The data could be stored in a different order which would explain why when you select some items another item information. An easy way to test this would be to place a log statement inside of the onItemClick to print out the string representation of the list item.

If this is indeed your problem a possible solution would be to call ProduitsAdapter.getItem() on your reference to the adapter inside of onItemClick to get the actual item that corresponds to 'pos'.

Android listview item click is not working

I too faced this issue, I overcome from this issue by setting click listener to convertView of custom adapter. I don't know is this good approach but it solved my issue.

public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
KeepassDBGroupv1 rowItem = getItem(position);

LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.custom_list_row, null);
holder = new ViewHolder();
holder.name = (TextView) convertView.findViewById(R.id.textView_group_entry_name);
holder.imageView = (ImageView) convertView.findViewById(R.id.imgView_group_entry_icon);
holder.type = (TextView) convertView.findViewById(R.id.textView_group_entry_type);
convertView.setTag(holder);
} else
holder = (ViewHolder) convertView.getTag();

holder.name.setText(rowItem.getGroupName());
holder.type.setText("Group");
Drawable d = context.getResources().getDrawable(context.getResources().getIdentifier("ic"+Integer.toString(rowItem.getImageId()), "drawable", context.getPackageName()));
holder.imageView.setImageDrawable(d);
//App.getDB().drawFactory.assignDrawableTo(holder.imageView, context.getResources(), rowItem.icon);
convertView.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Log.v("OpenDbListAdapter ","List View Clicked");
}
});
return convertView;
}

Listview Itemclick event not firing android xamarin

Your Adapter has to inherit from BaseAdapter<T> or ArrayAdapter<T>.

public class MyListAdapter : BaseAdapter<jtaskItem> { /* ... */ }

See: https://developer.xamarin.com/guides/android/user_interface/working_with_listviews_and_adapters/part_2_-_populating_a_listview_with_data/#Implementing_a_ListAdapter



Related Topics



Leave a reply



Submit