【问题标题】:Listview Item Imageview on click Issue单击问题时的 Listview 项目 Imageview
【发布时间】:2013-12-04 22:42:36
【问题描述】:

我在 listview 中有 imageview。 我正在使用自定义适配器来绑定数据。 我在 imageview 单击时显示相同列表视图的 textview 文本的吐司。 但它显示随机文本视图文本。 这是我的代码

  localfilename=tvlfilename.getText().toString();
  ImageView thumb_image=(ImageView)vi.findViewById(R.id.ivnotificationpreview); 
   thumb_image.setOnClickListener(new OnClickListener(){

    @Override
    public void onClick(View v) {
        Toast.makeText(mCtx, localfilename, Toast.LENGTH_SHORT).show();

    }});

【问题讨论】:

  • 这是因为ListView的回收机制。使用setTag()getTag() 来维护被点击的确切数据。 Have a reference blog of mine
  • 那我现在该怎么办?
  • 您可以发布更多代码 - 您在哪里检索点击时的项目​​索引?

标签: android android-listview


【解决方案1】:

localfilename=tvlfilename.getText().toString(); 放入onClick() 方法中。您必须在点击事件时获取 localfilename 值

试试这个方法

  ImageView thumb_image=(ImageView)vi.findViewById(R.id.ivnotificationpreview); 
  thumb_image.setOnClickListener(new OnClickListener(){

    @Override
    public void onClick(View v) {
        localfilename=tvlfilename.getText().toString();
        Toast.makeText(mCtx, localfilename, Toast.LENGTH_SHORT).show();

    }});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多