My listview is no click

0

I do not know why, but the items do not click.

My layout:

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:layout_gravity="center"
        android:src="@drawable/manager"
        android:background="#9b1136">
    </ImageView>

    <ListView
        android:layout_marginTop="10dp"    
        android:id="@+id/lista"            
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>   

</LinearLayout>

Activity:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ActionBar bar = getActionBar();
    bar.hide();

    listView = (ListView) findViewById(R.id.lista);

    listView.setOnItemClickListener(this);

}

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    // TODO Auto-generated method stub

    Toast.makeText(DiretorioView.this, "teste", 1000).show();   

}

Items

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:orientation="horizontal">

    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:padding="5sp">

        <Button
            android:id="@+id/imageview"
            android:layout_marginLeft="20dp"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:drawableTop="@drawable/lixo"
            android:text="Button" />

        <TextView
            android:id="@+id/text"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textSize="20dp"
            android:layout_marginLeft="14sp"
            android:textStyle="bold"
            android:textColor="#FFFFFF"
            android:gravity="center_vertical"/>         

    </LinearLayout>
</LinearLayout>
    
asked by anonymous 27.01.2015 / 15:29

1 answer

1

This problem occurs when you have an item in your list that has a focus, (its Button ), which causes the OnItemClickListener ( see this bug reported here )

This does not mean that you can not have a button inside a list, you can use (depending on your need):

1) Enter the android:descendantFocusability="blocksDescendants" parameter in the parent of your item in the list, and implement the button click normally on your adapter, for example:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
...
            Button btn= (Button) convertView.findViewById(R.id.youtButton);
            btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    ...
                }
            });
...
}

2) Put in the tag of your Button the parameter android:focusable="false" and android:focusableInTouchMode="false"

    
27.01.2015 / 16:00