2
我有一個ListView。我需要在條件(true)上的listView上添加項目。我試圖清除適配器,然後添加true items.And也試圖刪除錯誤的項目。但似乎我錯過了一些東西。 幫我找到我缺少的東西。清除適配器,然後添加項目,錯誤修復
這裏是主要活動
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;
}