在我的應用程序中,我有一個帶有「部分」的ListView。對於每個項目,我都添加了一個字母,但僅對於以該字母開頭的第一個字詞纔可見。它工作正常,但如果我在我的ListView中向下滾動,訂單更改,這意味着該信件將轉到下一個項目。ListView刷新GetView()
例子:
A
--
- Alligator
- Ant
- Antelope
- Ape
但是,當我向下滾動,會發生以下情況:
- Aligator
A
--
- Ant
- Antelope
- Ape
功能,增加了我在GetView()
我該如何解決實施信這個問題? 我讀過ListView在滾動時刷新,我該如何禁用刷新?還是有另一種方法來解決這個問題?
protected string old_char = "";
public override View GetView(int position, View convertView, ViewGroup parent)
{
var item = sw_items [position];
View view;
convertView = null;
view = (convertView ??
this.context.LayoutInflater.Inflate (Resource.Layout.ItemLayout,
parent,
false)) as LinearLayout;
var txtTitle = view.FindViewById<TextView> (Resource.Id.txtTitle);
txtTitle.SetText (sw_items [position].name, TextView.BufferType.Normal);
var alfabet = view.FindViewById<TextView> (Resource.Id.alfabet);
var linAlfabet = view.FindViewById<LinearLayout> (Resource.Id.Lin_Alfabet);
if (convertView == null) {
string cnv_char = item.name [0].ToString().ToUpper();
alfabet.Text = cnv_char;
if (cnv_char != old_char) {
alfabet.Visibility = ViewStates.Visible;
linAlfabet.Visibility = ViewStates.Visible;
} else {
alfabet.Visibility = ViewStates.Gone;
linAlfabet.Visibility = ViewStates.Gone;
}
//saving previous char
old_char = cnv_char;
}
return view;
}
}
我在做什麼錯?
添加您在適配器上使用的代碼。 – madlymad 2013-03-14 09:33:10