Reputation: 13
I am using listview
with Customlist
Adapter, I am able to set data to list but not able to assign onItem click listener to list. Some of the code snippet is as follows :
private ListView listview;
listview = (ListView) findViewById(R.id.mainOptionList);
customlistviewadapter = new CustomListViewAdapter(this, R.layout.listview_item_row, elements);
listview.setAdapter(customlistviewadapter);
With this I am able to assign data to list. I have attached clicklistener as follows :
listview.setOnItemClickListener(this);
@Override
public void onItemClick(AdapterView<?> adapter, View view, int position, long arg) {
System.out.println("position" + position + " item at this position:" + adapter.getItemAtPosition(position));
}
Here I am not able to print output in logcat
. Can somebody help me to resolve this issue?
Upvotes: 1
Views: 88
Reputation: 1442
You just try to put toast on the click listener
You just Use this code inside your Main Activity...
sListStudies.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View view,
int position, long arg) {
Toast.makeText(
MainActivity.this,
"position" + position + " item at this position:"
+ adapter.getItemAtPosition(position),
Toast.LENGTH_LONG).show();
}
});
Upvotes: 0
Reputation: 18933
In your custom file named listview_item_row set this properties
android:focusable="false"
android:focusableInTouchMode="false"
for your all UI elements.
Upvotes: 1