OnItemClickListener on a ListView inside a Fragment not working

后端 未结 7 1502
粉色の甜心
粉色の甜心 2020-12-29 09:11

EDIT: SOLVED. If there\'s anything focusable in the XML of the items, it will break the touch of the list, in other words, android:focusable=false to all the checkbo

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-29 09:37

    Here's a code snippet that'll do what you want.

    ListView lv;
    
    //code to get the listView instance using findViewByID etc
    
    lv.setOnItemClickListener(new OnItemClickListener()
    {
        @Override public void onItemClick(AdapterView arg0, View arg1,int position, long arg3)
        { 
            Toast.makeText(EnclosingActivity.this, "Stop Clicking me", Toast.LENGTH_SHORT).show();
        }
    });
    

    People usually trip on this, see if you have got this covered:

    All clicks and call backs (eg: the menu/actionbar callbacks) are sent to the activity the fragment is bound to, so they must be in the activity class and not the fragment class.

提交回复
热议问题