ListFragment OnListItemClick not being called

后端 未结 11 1414
盖世英雄少女心
盖世英雄少女心 2020-11-27 05:53

I have a class that extends ListFragment, and it overrides the OnListItemClick method. I am also doing this in another ListFragment the same way (and the method gets called)

相关标签:
11条回答
  • 2020-11-27 06:25

    I spent hours trying to figure out my own similar problem. I had a fairly simple compound text view that contained a checkbox and two textviews and a simple custom adapter. After trying various things that were suggested, I took out views until I just had one textview. Still didnt work. Do you know what did? I just deleted the xml layout file for the custom view I was using and made it again, piece by piece. Made the same exact thing with the same name. It just didn't like that file for some reason. So there you go. Some weird glitch in Eclipse I guess.

    0 讨论(0)
  • 2020-11-27 06:33

    I encountered the same problem after converting my app from a ListActivity to a ListFragment.

    The ListFragment was the only fragment of the activity (no tabs, etc), but the ListFragment was not seeing any of the clicks.

    The problem was that my Activity was still defined as a ListActivity. Changed it to a activity fixed it, and now the ListFragment sees the clicks.

        public class MyActivity extends ListActivity {
            @Override
            public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
                setContentView(R.layout.my_layout);
        }
    

    should have been:

        public class MyActivity extends Activity {
            @Override
            public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
                setContentView(R.layout.my_layout);
        }
    
    
    
        <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >        
            <fragment class="com.davidmarkscott.myapp.MyFragment"
            android:id="@+id/fragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
        </LinearLayout>
    
    0 讨论(0)
  • 2020-11-27 06:38

    Echoing what @auselen said above, in my case I had android:textIsSelectable="true" set in a TextView, and it was stealing the callback.

    Setting this to false solved the problem.

    0 讨论(0)
  • 2020-11-27 06:38

    A CheckBox is focusable by default. This means that a click on a list item will be interpreted as toggling the CheckBox and will not reach your onListItemClick(…) method. This internal quirk of ListView means that any focusable widget that appears in a list item layout (like a CheckBox or a Button) should be made non-focusable to ensure that a click on a list item will work as you expect. Because your CheckBox only reports information and is not tied to any application logic, there is a simple solution. You can define the CheckBox as not focusable.

    from The Big Nerd Ranch Guide book

    0 讨论(0)
  • 2020-11-27 06:39

    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.

    0 讨论(0)
提交回复
热议问题