HI all,Android:帶有自定義ArrayAdapter的ListView在長列表上動作 - 定時問題!
我有這個「搜索結果」ListView。 搜索結果可以是不同的「種類」(不同的部分,稱之爲)。 要分離「種類」,我添加一個標題行。 (我知道可擴展列表,但不能用於其他原因)。
在我的getView()中,我檢查一個屬性,如果它被設置,我改變了該行的背景顏色。
問題:當我運行一個只返回幾行(比如15)的查詢時,一切正常。但是當我運行另一個返回的時候,比如說600行,有些東西會變得怪異,並且它隨機地以一定的時間間隔改變背景。當我在調試模式下運行並在中間停止時,同樣的事情發生。
所以,這絕對是一個時間問題。
我在想這可能是由於屏幕鍵盤關閉時不得不重新渲染大列表。
那麼,是適配器的責任?有沒有解決方案?
如果鍵盤出現問題,是否有機制在開始渲染之前告訴列表「等到事物關閉」? (不知道我喜歡那樣,但是比得到一條可愛的小彩虹更好......)
謝謝!
Llappall
-
這裏的適配器和元素的佈局(如下圖):
private class ElementAdapter extends ArrayAdapter<Element> {
private ArrayList<Element> rows;
private Element.typeEnum type;
public ElementAdapter(Context context, int textViewResourceId, ArrayList<Element> rows) {
super(context, textViewResourceId, rows);
this.rows = rows;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.element, null);
}
Element row = rows.get(position);
if (row == null) {
return v;
}
v.setTag(row);
type = row.getType();
boolean isSectionType = type == Element.typeEnum.DIV118SECTION || type == Element.typeEnum.APPASECT ||
type == Element.typeEnum.APPBSECT || type == Element.typeEnum.AZSECT;
TextView title = (TextView) v.findViewById(R.id.title);
TextView body = (TextView) v.findViewById(R.id.body);
if (isSectionType) {
body.setMaxLines(5000);
}
title.setText(row.getTitle());
if (row.getBody() != null) {
body.setText(row.getBody());
}
if (type == Element.typeEnum.SEARCHLISTHEADER) {
v.setBackgroundColor(Color.rgb(230, 230, 250));
title.setBackgroundColor(Color.rgb(230, 230, 250));
body.setBackgroundColor(Color.rgb(230, 230, 250));
star.setBackgroundColor(Color.rgb(230, 230, 250));
}
return v;
}
}
==元LAYOUT ==
<TextView
android:id="@+id/body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
style="@style/ListItemSubTitle" />
</LinearLayout>
我將適配器和佈局附加到原始問題。謝謝你的幫助! – llappall 2011-05-09 16:49:06