ListView OnItemClickListener Not Responding?

2019-01-02 20:39发布

I've looked everywhere for a solution to this, but I can't figure out how to implement it. My OnItemClickListener was disabled somehow on my ListView rows, because I have an ImageButton in the row layout, which takes over the focus. There have been numerous questions I've found, but none of them have gotten me anywhere.

I've checked this question, but I couldn't really make heads or tails of it. I just need a way to get the rows clickable so that I can detect when a row is pressed. Long press and focus work fine.

13条回答
初与友歌
2楼-- · 2019-01-02 20:44

I have sub-classed ImageButton and setFocusable="false" in layout definition didn't work for me. It solved calling setFocusable(false) in constructor of subclass.

查看更多
其实,你不懂
3楼-- · 2019-01-02 20:47

This will definitely work. Add this to the layout definition.

android:descendantFocusability="blocksDescendants" 

Found the solution here

查看更多
若你有天会懂
4楼-- · 2019-01-02 20:52

best way to do is this:

  android:focusable="false"
  android:focusableInTouchMode="false"

set these properties for that Imagebutton and try. I

查看更多
姐姐魅力值爆表
5楼-- · 2019-01-02 20:52

Using a ScrollView can prevent the onItemClickListener from receiving the input.

Hope this helps anyone.

查看更多
余生无你
6楼-- · 2019-01-02 20:54
    listView= (ListView) findViewById(R.id.listview_names);

   listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
       @Override
       public void onItemClick(AdapterView<?> parent, View view, int position, long id)
       {
           Toast.makeText(getBaseContext(),"Clicked Button",Toast.LENGTH_LONG).show();
           Log.d("h","clicked");

           /* Intent intent=new Intent(MainActivity.this,Display_data.class);

            intent.putExtra("NAME",n);
            intent.putExtra("AGE",a);
            startActivity(intent);*/
       }
   });

Y this toast isn not working

查看更多
姐姐魅力值爆表
7楼-- · 2019-01-02 20:57

set your ImageButton's attribute:

android:focusable="false"

Because AbsListView.onTouchEvent check child.hasFocusable().

查看更多
登录 后发表回答