我的ListView
是一個簡單的ListView,但他有問題。
我正在使用一個SimpleCursorAdapter
,調用adapter
,我希望TextView加粗,並在單擊某個項目時更改背景。我也想要其他以前受影響的ListView項目重置自己。在ListView中重置視圖
以下是onListItemClick
事件的代碼。此代碼重置可見列表項目。並正確加粗所選項目。但是,當用戶隨機滾動TextViews
爲粗體時,我認爲是因爲視圖正在回收。
因此,onClick我想重置任何以前點擊的textViews和粗體單擊的項目。
我的工作不正常代碼:
@Override
public void onListItemClick(ListView listView, View view, int position, long id)
{
super.onListItemClick(listView, view, position, id);
//Tablet
for (int i = 0; i < adapter.getCount(); i++)
{
View mView = listView.getChildAt(i);
if (mView != null)
{
//Reset Bold text to default
TextView mtv = (TextView)mView.findViewById(R.id.Name);
mtv.setTypeface(null, Typeface.BOLD);
LinearLayout ll = (LinearLayout)mView.findViewById(R.id.itemlayout);
ll.setBackgroundDrawable(null);
}
}
TextView tv = (TextView)view.findViewById(R.id.Name);
tv.setTypeface(null, Typeface.NORMAL);
LinearLayout ll = (LinearLayout)view.findViewById(R.id.itemlayout);
ll.setBackgroundResource(R.drawable.dashboard_list_selector);
}
}