Do Not Receive OnItemClick ListView Event

I use one user list. When I click on listview, I did not get onClick Event.

Here is my code.

lvlList = (ListView)findViewById(R.id.lvlList); lvlList.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> a, View v,int position, long id) { Toast.makeText(getBaseContext(), "Click", Toast.LENGTH_LONG).show(); } }); lvlList.setAdapter(new OrderAdapter(getBaseContext())); 

OrderAdapter

 private class OrderAdapter extends BaseAdapter { private LayoutInflater mInflater; public OrderAdapter(Context context) { mInflater = LayoutInflater.from(context); } public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { convertView = mInflater.inflate(R.layout.example, null); holder = new ViewHolder(); holder.txtTest = (TextView) convertView.findViewById(R.id.txtTest); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.txtTest.setText(Util.SampleTest.get(position)); return convertView; } public class ViewHolder { public TextView txtTets; } public int getCount(){return Util.SampleTest.size();} public Object getItem(int position){return position;} public long getItemId(int position){return position;} } 
+6
android listviewitem
source share
6 answers

You need to set android:descendantFocusability="blocksDescendants" in your custom xml layout file for LinearLayout or in any other layout you used. (to define your custom string)

This should solve your problem. Because she solved my problem. If she decides, please mark my post as your answer.

You can also refer to the comments here.

+19
source share

If you have items with a click in your list, you must play with focus in order to be able to receive both the click event and the list item. Click the "Events" button.

Call the following code on your list items when they are created:

 listItem.setDescendantFocusability(FOCUS_BLOCK_DESCENDANTS); 

Found at http://code.google.com/p/android/issues/detail?id=3414 , answer # 27

+5
source share

check this out: ListView with interactive / editable widgets

+3
source share

Install the adapter first, and then set the clicker event for listview. Then try again.

0
source share

Make sure your custom layout does not have a CheckBox before the potential TextView . You can use ImageView to perform CheckBox functions.

0
source share

try it.

  if (convertView == null) { convertView = mInflater.inflate(R.layout.example, null); holder = new ViewHolder(); holder.txtTest = (TextView) convertView.findViewById(R.id.txtTest); convertView.setClickable(true); convertView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { } } convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.txtTest.setText(Util.SampleTest.get(position)); return convertView; } 
0
source share

All Articles