我想在单击其上的图像时获取android中的ListViewItem名称

时间:2013-02-12 11:46:11

标签: android listview onclick

当我单击listView项目上的编辑图像时。 我把onClickEvent放在我的适配器上。 我希望通过我的主要活动获取该文本视图的位置或名称。

建议,拜托?

public View getView(final int position, View convertView, ViewGroup parent) {
        View v = convertView;
      if (v == null) {
          final Context context = getContext();
                LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.transferlistviewitem_layout, null);
      }

      TransferEntry item = transferList.get(position);
      if (item != null) {
                TextView name = (TextView) v.findViewById(R.id.transferName_textView);
                ImageView delete = (ImageView) v.findViewById(R.id.edit_icon);

                delete.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {                       
                        t.setText(transferList.get(position).getItemName());                                                 
                    }
              });*/

2 个答案:

答案 0 :(得分:1)

是的,您可以从TextView listItem点击聆听方法获取文字           列表显示。通过这段代码:

 TextView name = (TextView) v.findViewById(R.id.textview_id);  

这里v是OnItemClick事件处理程序的视图。当您单击该项时,您可以轻松地通过此TextView获取文本。

答案 1 :(得分:0)

我已经知道了答案。

在我的Adapter Constructor上,我有一个参数,它是我的MainActivity的实例,并将其设置为适配器中的MainActivity实例。 :)