Adding a button to each line in the list

I want to add a button to every line of my list. I created an XML file with a name row.xmlin my layout folder and added two text images and a button in this file. But when the button is added, I cannot click on the list item. I can only press a button. Here row.xml:

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


    <TextView
        android:id="@+id/text11"

        android:layout_alignParentLeft="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
  android:textSize="25sp"
  android:textColor="#000000"
         />
          <TextView
        android:id="@+id/text2"

        android:layout_alignParentLeft="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
  android:textSize="10sp"
    android:textColor="#000000"
         />
          <Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>

I want to link to textviews and a button in my activity. Please help me and suggest some ideas.

+5
source share
6 answers

. , android:focusable="false" .

+8

( ). getView onClickListener TextView, , ListItem .

+1

- LINK

, .

+1

focusable = "false",

<Button
        android:id="@+id/bt_do"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        **android:focusable="false"** />

public class MyAdapter extends BaseAdapter {
    private Context context;
    private List< Objet > objects;
    private OnClickListener listener;

    public MyAdapter(Context context, List<Objet> objects,
            OnClickListener listener) {
        this.context = context;
        this.objects = objects;
        this.listener = listener;
        // TODO Auto-generated constructor stub
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater infalInflater = ((Activity) context)
                    .getLayoutInflater();
            convertView = infalInflater.inflate(R.layout.my_line_list, null);
        }
        Button bt_do=(Button)convertView.findViewById(R.id.bt_do);
        bt_do.setOnClickListener(listener);
        return convertView;

    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return objects.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return objects.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

}

un adapter .

+1

, ...

http://commonsware.com/Android/excerpt.pdf

pdf . 104 . .

Hope this solves your problem.

0
source

All Articles