Onlistitemclick Is Not Working for Listview

onListItemClick is not working for listview?

Add below code to your TextView in the XML

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

and try again.

Another simple solution: add android:descendantFocusability="blocksDescendants" to the root viewgroup.

listview item with button not responding to onListItemClick

you can create View.OnClickListner object which can listen your imagebutton click in getView. onListItemClick generally used to handle row click event not items in rows.

public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflator = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View listItem = inflator.inflate(R.layout.medcince_list_item, null);

ImageButton mEdit = (ImageButton)listItem.findViewById(R.id.item_edit);
mEdit.setOnClickListener(new View.OnClickListener(){

@Override
public void onClick(View v) {
// HERE YOU CAN HANDLE BUTTON CLICK. POSITION YOU CAN HAVE FROM getView already.
}

});
mEdit.setTag(getItem(position));

ImageButton mHistory = (ImageButton)listItem.findViewById(R.id.item_history);
mHistory.setOnClickListener(new View.OnClickListener(){

@Override
public void onClick(View v) {
// HERE YOU CAN HANDLE BUTTON CLICK. POSITION YOU CAN HAVE FROM getView already.
}

});
mHistory.setTag(getItem(position));

return listItem;
}

ListFragment OnListItemClick not being called

If you have an item in your layout that can steal input from other components like a CheckBox, that component needs to be defined as not focusable.

onListItemClick doesnt work with my ListView

It's possible to construct your ListView by extending ListActivity rather than Activity - onListItemClick will only work as it is used in you code if you extend ListActivity. You can also unimplement OnClickListener regardless of what you do. For instance:

public class MainActivity extends ListActivity {

String[] titles = { "One", "two", "three", "four", "five"};
String[] beschreibung = { "1", "2", "3", "4", "5"};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// VivzAdapter? Good to see another SlideNerd fan :)
VivzAdapter adapter = new VivzAdapter(this, titles, beschreibung);
setListAdapter(adapter);
}

protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String cheese = titles[position];
try {
Class ourClass = Class.forName("com.example.benice." + cheese);
Intent ourIntent = new Intent(this, ourClass);
startActivity(ourIntent);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}

This will work for as long as you have other Classes called "One", "two", "three" etc. You also need to alter the construction of your getView() method in the custom ArrayAdapter.

public View getView(int position, View convertView, ViewGroup parent) {
View row;

if (convertView == null) {
LayoutInflater inflator = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflator.inflate(R.layout.row, parent, false);
} else {
row = convertView;
}

TextView titles = (TextView) row.findViewById(R.id.titleTextView);
TextView beschreibung = (TextView) row.findViewById(R.id.beschTextView);

titles.setText(titlesArray[position]);
beschreibung.setText(beschreibungArray[position]);

return row;
}

This post goes into more depth on onListItemClick.

ListActivity's onListItemClick does not work

Try to also set the CheckBox from the row layout as not focusable:

//...
<CheckBox
android:id="@+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="4px"
android:layout_marginRight="10px"
android:focusable="false"
android:clickable="true">

//...

onListItemClick doesn't work

I found an answer to solve this by adding android:focusable="false" inside of the the views in the listview/customlayout that will be imported to the activity. I got the answer from this link:
onListItemClick is not working for listview?

onListItemClick not working in fragment

You will need to add a OnItemClickListener as this for ListView:

myListView.setOnItemClickListener(new OnItemClickListener() { 
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

//your code over here
}
});

Hope this helps.

Android ListView - onListItemClick does not work properly

After playing around with virtually every attribute in my TextView, I finally found the reason why it was not working. It was because of the attribute android:inputType="text" in my TextView. I'm not sure why I added that piece of code (I probably copied the TextView from one of my other applications), but removing it solves my problem.

onlistitemclick in AppCompatActivity

Do this

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Note note = posts.get(position);
Intent intent = new Intent(this, EditNoteActivity.class);
intent.putExtra("noteId", note.getId());
intent.putExtra("noteTitle", note.getTitle());
intent.putExtra("noteContent", note.getContent());
startActivity(intent);
}
});


Related Topics



Leave a reply



Submit