Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个包含 4 个相同行的列表视图。在这些行中,我有一个包含 TextView (id : R.id.notif) 的 RelativeLayout。在我的 Activity 中,我使用自己的 ArrayAdapter。
我希望能够修改第三行的文本。我试过这个,但它不工作。
((TextView)listview.getAdapter().getView(2, null, listview).findViewById(R.id.notif)).setText("50");
谢谢你。
不要adapter.getView()用于那个!此方法在适配器内部用于创建显示在列表中的视图!执行此操作的正确方法是修改基础数据并使用 刷新列表adapter.notifyDataSetChanged()。不要尝试直接访问列表中的视图,您不知道它们是当前可见还是滚动到视图之外。
adapter.getView()
adapter.notifyDataSetChanged()