【问题标题】:Display hide button in listView from a listener从侦听器显示 listView 中的隐藏按钮
【发布时间】:2012-10-12 03:53:05
【问题描述】:

我还有一个很好的问题要问你...^^

我有一个带有 Button 项的 listView 和一个 ItemClickListener 在这个列表上。

当我点击一个item时,我想显示当前点击item的Button,而不需要重新加载所有listView。

你知道我该怎么做吗?

这是我的代码:

public ListView.OnItemClickListener listviewProductsOnItemClickListener =
        new ListView.OnItemClickListener(){

    public void onItemClick(AdapterView<?> currentAdapter, View currentView, int position, long id) {           
        Button changeQuantity = (Button) findViewById(R.id.changequantity);

        changeQuantity.setVisibility(View.VISIBLE);

    }
};

问题是按钮总是显示在第一个项目上:/

感谢您的帮助,再次对不起我的法语英语!

【问题讨论】:

  • 欢迎回来。。对不起,我不能完全理解你的问题。如果可能的话,你能详细解释一下吗??

标签: android listview button listener


【解决方案1】:

onItemClick 将为您提供来自适配器的 currentView,您将获得如下所示的按钮。

public void onItemClick(AdapterView<?> currentAdapter, View currentView, int position, long id) {           
    Button changeQuantity = (Button) currentView.findViewById(R.id.changequantity);

    changeQuantity.setVisibility(View.VISIBLE);

}

【讨论】:

    【解决方案2】:

    我认为更好的方法是在适配器的getView() 中定义点击侦听器。这样你就可以避免任何混淆..

    您也可以尝试使用

     public void onItemClick(AdapterView<?> currentAdapter, View currentView, int position, long id) {           
        Button changeQuantity = (Button) currentView.findViewById(R.id.changequantity);
    
        changeQuantity.setVisibility(View.VISIBLE);
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-13
      • 2019-08-23
      • 2019-04-30
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      • 2021-06-05
      • 1970-01-01
      相关资源
      最近更新 更多