回覆列表
  • 1 # 使用者5376756992906

    好久不寫Android了,如果我沒記錯的話

    1.直接寫在Activity裡面

    @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { CheckBox checkbox=v.findViewById(R.id.xx); }

    @Override

    public View getView( int position, View convertView, ViewGroup parent) {

    viewHolder.checkbox.setOnClickListener(new View.OnClickListener() {

    @Override

    public void onClick(View v) {

    }

    });

    }

    3.抽象回撥(上2回撥方法)

    public class MyAdapter extends BaseAdapter {

    @Override

    public View getView(int position, View convertView, ViewGroup parent) {

    ViewHolder holder;

    ......

    holder.checkBox.setOnClickListener(mListener);

    }

    public class ViewHolder {

    public CheckBox checkBox;

    }

    //用於回撥的抽象類

    public static abstract class MyClickListener implements OnClickListener {

    @Override

    public void onClick(View v) {

    myOnClick((Integer) v.getTag(), v);

    }

    public abstract void myOnClick(int position, View v);

    }

    }

    Activity:

    private MyClickListener mListener = new MyClickListener() {

    @Override

    public void myOnClick(int position, View v) {

    }

    };

  • 中秋節和大豐收的關聯?
  • 郭德綱和姜昆到底有什麼恩怨?