1

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?

1 Answer 1

4

Get rid of the ScrollView, or move the ListView outside of the ScrollView. Generally, you cannot have scrollable things inside of other scrollable things.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.