我有一個Android UI的問題,我似乎無法解決。 我的主要活動(a ListActivity
)顯示項目列表。當用戶點擊一個時,它會導致基礎數據通過AsyncTask
更新(從Web服務查詢)。當請求成功終止時,我呼叫notifyDataSetChanged()
顯示新信息。 這是我的理解是,從我的自定義BaseAdapter
的getView
方法將被調用執行渲染:TextView.settextColor影響多個項目
private List<InstalledApp> data;
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
if (convertView == null) {
convertView = LayoutInflater.from(ctx).inflate(R.layout.list_item, parent, false);
}
InstalledApp app = data.get(position);
String latest_version = app.getLatestVersion();
TextView version = (TextView) convertView.findViewById(R.id.version);
if (latest_version != null)
{
if (app.getVersion().equals(latest_version))
{
version.setText(app.getVersion());
version.setTextColor(Color.GREEN);
}
else
{
version.setText(app.getVersion() + " (Current: " + latest_version + ")");
version.setTextColor(Color.RED);
}
}
else {
version.setText(app.getVersion());
}
return convertView;
}
的問題是,當一個項目被更新,這個被調用,兩個項目都有自己的顏色變化。但文本內容仍然正確。第二個通常是不可見的,我必須向下滾動列表才能看到它。 你有什麼想法可能會造成這種情況?
這種情況bcoz的ListView回收VIE W上。發佈'InstalledApp'類 – Raghunandan
你能提供更多的細節樣本數據和發生了什麼... –