【问题标题】:Update ListView in ArrayAdapter when a row button clicked单击行按钮时更新 ArrayAdapter 中的 ListView
【发布时间】:2016-12-22 09:42:19
【问题描述】:

我有一个扩展 ArrayAdapter 的类 OwnAdapter。 它的数据在 arrayList 中传递。 有一个包含 2 个 TextView 和 2 个 Button 的自定义布局。 我已经在适配器本身的 getView 方法中定义了按钮的 onClick 操作。 单击行的按钮时,对数据库进行了一些更改。现在,当单击 2 个按钮中的任何一个并显示新数据时,我不知道如何更新列表视图。

bAttend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
                //works fine
                upDateAttend(position);

                //code for updating view-What to add here?
                notifyDataSetChanged();
            }
    });

【问题讨论】:

  • 使用 notifyDataSetChanged();每次更改后。
  • 是的,使用 yourAdapter.notifyDataSetChanged();确保您也更新了您的数组列表大小
  • @teckwei arraylist 大小没有改变,但是其中一行的内容正在改变
  • @maharith-aditya-s-s 我试过 notifyDataSetChanged(); ,但没有任何效果。
  • @srk20 您能在此处显示您的按钮单击侦听器代码,以便轻松判断问题所在

标签: android listview arraylist adapter


【解决方案1】:

更新你的数组列表后,制作这一行 youradapter.notifyDataSetChanged(); 如果您在 adpater 中更新 arraylist,只需添加 notifyDataSetChanged(); 看到这个链接,谈论recyclerview,但会帮助你 https://guides.codepath.com/android/using-the-recyclerview#notifying-the-adapter

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-18
    • 2012-05-13
    • 1970-01-01
    相关资源
    最近更新 更多