如何在BindView中添加Click事件?

时间:2011-05-09 21:21:10

标签: android adapter clicklistener

如何为具有绑定视图的适配器添加单击处理程序?刚开始。谢谢。

1 个答案:

答案 0 :(得分:1)

将其放入binderView中 - 无论如何我都会为我工作。

public void bindView(View v, Context context, final Cursor c) {

int tvGoto = c.getColumnIndexOrThrow("mColumn");
        final String gotoLink = c.getString(tvGoto);
        TextView gotoTxt = (TextView) v.findViewById(R.id.mRID);

        if (gotoTxt != null) {
            gotoTxt.setText(gotoLink);
        }
....

        v.setTag(gotoLink);

final ListView lv = getListView();
        lv.setEnabled(true);
        lv.setClickable(true);

        lv.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View v, int arg2,
                    long arg3) {

                String url = "";
                url = (String) v.getTag();

                Intent i = new Intent(QueryDisplay.this, DocView.class);
                QueryDisplay.this.startActivity(i);
            }
        });
}