Listview Onitemclicklistener Not Responding

ListView OnItemClickListener Not Responding?

Instead of an OnItemClickListener, add an OnClickListener to each of your views returned from your adapter. You'll need to use setItemsCanFocus setting up your list:

ListView list = (ListView) findViewById(R.id.myList);
list.setAdapter(new DoubleClickAdapter(this));
list.setItemsCanFocus(true);

and then in your Adapter's getView, this will yield a clickable row. The button is assumed to be in the inflated xml.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = View.inflate(context, R.layout.cell, null);
view.setClickable(true);
view.setFocusable(true);
view.setBackgroundResource(android.R.drawable.menuitem_background);
view.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
new AlertDialog.Builder(context).setTitle("touched").show();
}

});
return view;
}

ListView onItemClickListener not working. Onclick doesnot work

Paste the line (android:descendantFocusability="blocksDescendants") in you adapter xml parent layout and paste android:focusable="false" in the checkbox or button in the adapter xml file.

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 in Fragment - onItemClickListener not working

If you are using ListFragment then you can simply use its override method onListItemClick().

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);

// Your Stuff Goes Here
}

And also add android:descendantFocusability="blocksDescendants" in root layout of list element.

onitemclicklistener not working in custom listview

try this.. its working fine to me:

1.In your CustomAdapter Class inside getView() method ,put this following code.

convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(ctx,"Position :"+position+" clicked",Toast.LENGTH_LONG).show();
}
});

I hope this too help you.Let me know if it is working or not

Listview onitemclicklistener not working for Check box?

remove the focus to the checkbox in layout then it will work.

like this:

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"/>

or else you have to write that listener in adapter itself.



Related Topics



Leave a reply



Submit