0
當我使用JSON然後數據中顯示許多時間在listview.When i的列表視圖向下滾動然後再次重複數據顯示在列表視圖列表視圖數據顯示
class.cs綁定列表視圖
namespace HSAPP
{
class ContListViewSpecNameClass : BaseAdapter<GetSpecNames>
{
List<GetSpecNames> objList;
Activity objActivity;
public ContListViewSpecNameClass (Activity objMyAct,List<GetSpecNames> objMyList) : base()
{
this.objActivity = objMyAct;
this.objList = objMyList;
}
public override GetSpecNames this[int position]
{
get
{
return objList[position];
}
}
public override int Count
{
get
{
return objList.Count;
}
}
public override long GetItemId(int position)
{
return position;
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
var item = objList[position];
//View objView = convertView;
if (convertView == null)
{
convertView = objActivity.LayoutInflater.Inflate(Resource.Layout.ContListViewSpecName, null);
convertView.FindViewById<TextView>(Resource.Id.tvSpecID).Text = item.SpecID;
convertView.FindViewById<TextView>(Resource.Id.tvSpecName).Text = item.SpecName;
}
return convertView;
}
}
}
activity.cs
private void BindControl_BindSpecCompleted(object sender, BindControl.BindSpecCompletedEventArgs e)
{
jsonValue = e.Result.ToString();
if (jsonValue == null)
{
Toast.MakeText(this, "No Data For Bind", ToastLength.Long).Show();
return;
}
try
{
JArrayValue = JArray.Parse(jsonValue);
list = new List<GetSpecNames>();
int count = 0;
while (count < JArrayValue.Count)
{
GetSpecNames getSpecName = new GetSpecNames(JArrayValue[count]["SpecID"].ToString(), JArrayValue[count]["SpecName"].ToString());
list.Add(getSpecName);
count++;
}
listView.Adapter = new ContListViewSpecNameClass(this, list);
listView.ItemClick += ListView_ItemClick;
}
catch (Exception ex)
{
Toast.MakeText(this, ex.ToString(), ToastLength.Long).Show();
}
}
private void ListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
{
var curItem = list[e.Position];
Toast.MakeText(this, curItem.SpecID + ' ' + curItem.SpecName, ToastLength.Long).Show();
}
輸出: -
This is 2nd image when scroll down
請參閱本主題:http://stackoverflow.com/questions/19019775/list-item-repeating-in-android-customized-listview – HeisenBerg
公共ContListViewSpecNameClass(活動objMyAct,列表 objMyList):基座( ) { this.objActivity = objMyAct; this.objList = objMyList; } 這些是參考文獻 –
Y ..... it Worked。謝謝 – sagarpatre