Android ListView ClickEvent not working
NickName:Sahitya Kumar Suman Ask DateTime:2015-09-22T19:46:57

Android ListView ClickEvent not working

I am using Custom ListView in Android and everything is working fine fetching data into list. Earlier the click event working fine with it but when I applied custom TextView and LinerLayout with a custom background in litst_view_item.xml file its click event not working right now please help me. How can I remove this error ?

I tried all code samples like :

android:focusable="false"
android:focusableInTouchMode="false"

in every layout item in list_view_item.xml (even in linearlayout)

and

android:descendantFocusability="blocksDescendants"

in listview_activity.xml file

in listview attribute and in its parent LinearLayout.xml

Please if someone know about this problem, please help me

Copyright Notice:Content Author:「Sahitya Kumar Suman」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/32716028/android-listview-clickevent-not-working

Answers
Manish kumar 2015-09-22T12:00:00

Remove android:descendantFocusability=\"blocksDescendants\" from listview_activity.xml and add it in top-level layout of list_view_item.xml.",


Nouran S. Ahmad 2015-09-22T12:56:06

try using custom listView Adapter, and add onClick listener to the view layout like this:\n\npublic listviewAdapter(Activity activity, ArrayList<String> list) {\n\n this.activity = activity;\n this.list = list;\n\n }\n @Override\n public int getCount() {\n return list.size();\n }\n @Override\n public Object getItem(int position) {\n return list.get(position);\n }\n @Override\n public long getItemId(int position) {\n return position;\n }\n private class ViewHolder {\n LinearLayout linearLayout;\n TextView txtview; \n\n\n }\n\n @Override\n public View getView(final int position, View convertView, ViewGroup parent) {\n\n ViewHolder holder;\n LayoutInflater inflater = activity.getLayoutInflater();\n\n if (convertView == null){\n\n convertView = inflater.inflate(R.layout.listview_row, null);\n\n holder = new ViewHolder();\n holder.txtview = (TextView) convertView.findViewById(R.id.txtview);\n convertView.setTag(holder);\n }else{\n holder = (ViewHolder) convertView.getTag();\n holder.txtview.setText(list.get(position));\n convertView.setOnClickListener(new View.OnClickListener() {\n @Override\n public void onClick(View v) {\n //do something \n }\n });\n}}\n\n\nand in the onCreate you need to set the adapter to the list:\n\nlistviewAdapter adapter = new listviewAdapter(ActivityName.this, list);\nlistView.setAdapter(adapter);\n\n\nthis way you wont need to set an OnItemSelectedListener for the list.",


More about “Android ListView ClickEvent not working” related questions

Android ListView ClickEvent not working

I am using Custom ListView in Android and everything is working fine fetching data into list. Earlier the click event working fine with it but when I applied custom TextView and LinerLayout with a ...

Show Detail

Xamarin Android Listview ClickEvent doesn't work

I am pretty new here, but I have problem and hope that you can help me to solve it. I've created a ListView in Xamarin Android, VS 2017. After configuring it I tried to add a click Event in the

Show Detail

How to Refresh listview using getview of BaseAdapter on image clickEvent

public View getView(final int position, View v, ViewGroup parent) { Teami = (LayoutInflater) contextTeam .getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = Teami.inflate(com.

Show Detail

Changing Text Colors and ClickEvent of an Item inside a ListView(Xamarin Android)

The problem I am facing is I am unable to change the color of my Items inside the Listview to Black color. My ListView's background (Which I've removed in order to see the items inside Listview) is

Show Detail

How do implement ClickEvent on listview?

What should I do to achieve Click Event on listview ? Should I try OnItemClickListener or OnItemSelectedListener ?My code is here: Mainactivity.java package com.example.se_02.eventhand; import an...

Show Detail

Imageview clickevent gettag method in a listview row returns null

I had an ImageView in a listview row, the imageView had a clickevent when i click an imageview the getTag() method is returning always null. My layout file: &lt;?xml version="1.0" encoding="u...

Show Detail

Android ListView transparent background not working

android:divider transparency is not working. Setting a color (e.g. #BBF232) is working fine. Using "@android:color/transparent" as listview background is working properly aswell. Just when using it...

Show Detail

Inflate ListView with custom ArrayAdapter - onItemClick not working?

I tried almost everything for 2 days now, but can't get it to work. From a Service (also tried Activity) I inflate a listview oncreate: view = inflater.inflate(R.layout.my_listview, null); ...

Show Detail

Android clickable not working on listview

I want to use ripple effect for this I set to android:clickable="true" but when I do this onClick event is not working,but onLongClick is working.How can I resolve this ? If I don't set android:

Show Detail

Android ListView listSelector not working

I am trying to set a custom selector to a ListView. It's working fine on newer devices but not working on lower version of devices.I want the ListView selected item to be stay highlighted. Please ...

Show Detail