макет объекта для элемента документа

Одним из решений является создание CustomAdapter, который расширяет SimpleCursorAdapter. Затем переопределите метод bindView В bindView найдите Button, затем обработайте onClickEvent

public class CustomAdapter extends SimpleCursorAdapter {

    private Context mContext;
    private Context appContext;
    private int layout;
    private Cursor cr;
    private final LayoutInflater inflater;

    public CustomAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
        super(context, layout, c, from, to);
        this.layout = layout;
        this.mContext = context;
        this.inflater = LayoutInflater.from(context);
        this.cr = c;
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        return inflater.inflate(layout, null);
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        super.bindView(view, context, cursor);
        ...
        TextView tv_Name = (TextView) view.findViewById(R.id.tv_Name);
        tv_Name.setText(...);
        ...
        Button btnRemove = (Button) view.findViewById(R.id.btn_remove);
        btnRemove.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // button click
                // Remove your item here 

            }
        });
    }
}

Используйте его в Activity на

 final CustomAdapter sc = new CustomAdapter(this,R.layout.list_row2,ictemp, from, to, 0);
 lv.setAdapter(sc)

Надейтесь, что это помогает

29
задан Max 1 August 2017 в 11:59
поделиться