Reputation: 117
I am trying to find out how to implement a click handler for items in a ListView in Android.
I have a layout file that looks like this:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView03lr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="vertical">
<LinearLayout
android:id="@+id/Linear03lr"
android:layout_width="fill_parent"
android:orientation="vertical"
android:gravity="center"
android:layout_height="fill_parent">
<!--Put form controls here-->
<ListView android:id="@+id/ListView01"
android:layout_width="wrap_content"
android:layout_height="400dp" />
<Button
android:id="@+id/previousbutton"
android:gravity="center_horizontal"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent"
android:text="Previous Menu"/>
</LinearLayout>
</ScrollView>
..and an activity/class that has the following code in the OnCreate() method:
ListView lv1;
lv1=(ListView)findViewById(R.id.ListView01);
lv1.setTextFilterEnabled(true);
lv1.setOnItemClickListener(new OnItemClickListener() {
// @Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Toast.makeText(ListRecords.this,"Clicked!", Toast.LENGTH_LONG).show();
}
});
When I run this code, when I click an item in the ListView, nothing happens. Can someone help me with this?
Upvotes: 1
Views: 3798
Reputation: 1006734
Get rid of the ScrollView
, or move the ListView
outside of the ScrollView
. Generally, you cannot have scrollable things inside of other scrollable things.
Upvotes: 4