我有一个ListView。我需要在条件上添加listView上的项目(true)。我试图清除适配器,然后添加真项。并尝试删除虚假项目。但似乎我错过了一些东西。 帮我找到我错过的东西。
这是主要活动
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;
}
答案 0 :(得分:2)
这是我的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;
}
和视图
viewHolder.chapterName.setText(getFavoriveChapters().get(position).getTitle());
问题解决了:)