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.
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;
}
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'.
Click on list item of a ListView doesn't respond
You should define on all of the child objects in the item listview (TextView, ImageView etc.):
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
And for the root item RelativeLayout / LinearLayout and so, define:
android:clickable="false"
android:descendantFocusability="blocksDescendants"
android:focusable="false"
android:focusableInTouchMode="false"
If you won't define those, they will "catch" the click event.
And if you have a Custom listView adapter, just check that you override:
@Override
public boolean isEnabled(int position)
{
return true;
}
OnItemClickListener and OnClickListener not working for ListView
The following will do the job in your case.
ListView propertylistview = (ListView) findViewById(R.id.listview);
propertylistview.setOnItemClickListener( myListViewClicked ):
OnItemClickListener myListViewClicked = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(YourActivity.this, "Clicked at positon = " + position, Toast.LENGTH_SHORT).show();
}
};
Dont forget to remove the following from the CustomAdapter
convertView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(parent.getContext(), "view clicked: " + ListArray.getName(), Toast.LENGTH_SHORT).show();
}
});
ListView not responding to click events in Android
add
android:descendantFocusability="blocksDescendants"
to the top ViewGroup of your items
upd:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center_vertical"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:background="@android:color/transparent"
android:descendantFocusability="blocksDescendants"
>
<ImageView
android:id="@+id/profile_picture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/mr_unknown"
android:contentDescription="@string/profile_picture_description"
android:paddingRight="3dp"/>
<TextView
android:id="@+id/real_life_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/FriendListText"/>
<Button
android:id="@+id/ping_friend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ping Friend"
/>
</LinearLayout>
Related Topics
Double Tap: Zoom on Android Mapview
How to Crop a Bitmap for Imageview
How to Ask Permission to Access Gallery on Android M.
Install Xlsx and Rjava on MACos Mavericks 10.9.5
How to Encode String (Use Encrypt Messagedigest in Java) to Base64 String in Swift
Why Would One Declare an Immutable Class Final in Java
The Specified Dsn Contains an Architecture Mismatch Between the Driver and Application. Java
Prevent Webview from Displaying "Web Page Not Available"
How to Update Xml File from Another Xml File Dynamically
How to Programmatically Add Views and Constraints to a Constraintlayout
No Resource Identifier Found for Attribute 'Layout_Behavior' in Package
Resources.Openrawresource() Issue Android
Simple Program to Call R from Java Using Eclipse and Rserve
How to Do a Cross Platform Encryption Method Working in Both iOS and Android (Aes Encryption Only..)