gpt4 book ai didi

android - 清除适配器然后添加项目,错误修复

转载 作者:行者123 更新时间:2023-11-29 00:41:10 25 4
gpt4 key购买 nike

我有一个 ListView。我需要在 listView 上添加一个条件(true)的项目。我试图清除适配器然后添加真实的项目。并且还尝试删除错误的项目。但似乎我错过了什么。帮我找到我缺少的东西。

这是主要 Activity

protected void onCreate(Bundle savedInstanceState)
{

super.onCreate(savedInstanceState);
setContentView(R.layout.favorite_tab);

list = (ListView) findViewById(R.id.listView1);
mAdapter = new FavoriteListAdapter(this);

list.setAdapter(mAdapter);
getFavoriteChapt();
list.setOnItemClickListener(this);

}

public void getFavoriteChapt()
{
mAdapter.clear();
for (int i = 0; i < 17; i++)
{
if (DataStore.getHierarchicalChapters().getSubChapters().get(i)
.isFavorite() == true)
mAdapter.add(DataStore.getHierarchicalChapters()
.getSubChapters().get(i));
}
mAdapter.notifyDataSetChanged();
}

还有我的 CustomAdapter

    @Override
public View getView(int position, View convertView, ViewGroup parent)
{

View row = convertView;

if (row == null)
{
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.favorite_tab_list_view_row, parent,
false);
ViewHolder viewHolder = new ViewHolder();
viewHolder.text_view_sura_name = (TextView) row
.findViewById(R.id.searchChapterTextViewId);

row.setTag(viewHolder);
}
ViewHolder viewHolder = (ViewHolder) row.getTag();

viewHolder.text_view_sura_name.setText(Integer.toString(position)
+ DataStore.getHierarchicalChapters().getSubChapters()
.get(position).getTitle());

return row;
}

最佳答案

这是我的 geFavoriteChapters

private ArrayList<Chapter> getFavortiveChapters()
{
ArrayList<Chapter> chapter = new ArrayList<Chapter>();

for (int i = 0; i < 17; i++)
{
if (DataStore.getHierarchicalChapters().getSubChapters().get(i)
.isFavorite())
chapter.add(DataStore.getHierarchicalChapters()
.getSubChapters().get(i));
}
return chapter;
}

和 View

viewHolder.chapterName.setText(getFavoriveChapters().get(position).getTitle());

问题解决了:)

关于android - 清除适配器然后添加项目,错误修复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9262143/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com