У меня есть 4 прядильника на одной странице макета и каждый из них имеет различный набор данных с сервера. Я использовал метод Base-Adapter (GETVIEW) для установки части элемента отображения.Одиночный класс адаптивного адаптера для нескольких разворотов
Мой вопрос: Можно ли использовать один класс базового адаптера для нескольких элементов управления счетчиком? Как установить другую часть элемента отображения в методе GETVEW?
Примечание. Мы используем службу WCF RESTful для получения онлайн-данных.
Найдите ниже пример кода в базовом адаптере.
class EyeColorAdapter : BaseAdapter<MMS>
{
List<MMS> items;
Activity context;
public EyeColorAdapter(Activity context, IEnumerable<MMS> items)
: base()
{
this.context = context;
this.items = items.ToList();
}
public override long GetItemId(int position)
{
return position;
}
public override MMS this[int position]
{
get { return items[position]; }
}
public override int Count
{
get { return items.Count; }
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
View view = convertView;
if (view == null)
{
view = context.LayoutInflater.Inflate(Android.Resource.Layout.SimpleListItem1, null);
}
// This is single spinner control display part. How to Check multiple spinner control condition here to set Display member part.
view.FindViewById<TextView>(Android.Resource.Id.Text1).Text = items[position].WONO.ToString();
view.FindViewById<TextView>(Android.Resource.Id.Text1).SetTextColor(Android.Graphics.Color.Black);
return view;
}
}
Activitiy Класс:
public class Activity1 : Activity
{
List<MMS> items1;
protected override void OnCreate(Bundle bundle)
{
try
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
var request = HttpWebRequest.Create("http://192.168.0.72/eFACiLiTYPhone/mobileservice/WinPhoneWCFService.svc/listingworkorder/x");
request.ContentType = "application/json";
request.Method = "GET";
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
var content = reader.ReadToEnd();
if (string.IsNullOrWhiteSpace(content))
{
Console.Out.WriteLine("Response contained empty body...");
}
else
{
Console.Out.WriteLine("Response Body: \r\n {0}", content);
}
List<MMS> myDeserializedObjList =
(List<MMS>)Newtonsoft.Json.JsonConvert.DeserializeObject(content, typeof(List<MMS>));
Spinner spinr = FindViewById<Spinner>(Resource.Id.spinner1);
spinr.Adapter = new EyeColorAdapter(this, myDeserializedObjList);
}
}
var request1 = HttpWebRequest.Create("http://192.168.0.72/eFACiLiTYPhone/mobileservice/WinPhoneWCFService.svc/listingworkorder/x");
request1.ContentType = "application/json";
request1.Method = "GET";
using (HttpWebResponse response1 = request1.GetResponse() as HttpWebResponse)
{
using (StreamReader reader1 = new StreamReader(response1.GetResponseStream()))
{
var content1 = reader1.ReadToEnd();
if (string.IsNullOrWhiteSpace(content1))
{
Console.Out.WriteLine("Response contained empty body...");
}
else
{
Console.Out.WriteLine("Response Body: \r\n {0}", content1);
}
List<MMS> myDeserializedObjList1 =
(List<MMS>)Newtonsoft.Json.JsonConvert.DeserializeObject(content1, typeof(List<MMS>));
Spinner spinr1 = FindViewById<Spinner>(Resource.Id.spinner2);
spinr1.Adapter = new EyeColorAdapter(this, myDeserializedObjList1);
items1 = myDeserializedObjList1;
int index = items1.IndexOf(items1.Where(x => x.WONO + "" == Convert.ToString("INDIA2085")).FirstOrDefault());
spinr1.SetSelection(index);
}
}
}
catch (Exception ex)
{
Toast.MakeText(this, ex.InnerException.ToString(), ToastLength.Long);
}
}
}
public class MMS
{
public string WONO { get; set; }
public string EquipmentNo { get; set; }
public string Status { get; set; }
public string JobDescription { get; set; }
public object Raised { get; set; }
public string Hier { get; set; }
}
Я новичок в разработке Andriod. Пожалуйста, направляйте меня, если мое понимание ошибочно.
Вы можете написать свой код своей деятельности? – Vikram
Я обновил свой класс активности. Пожалуйста, обратитесь к – Kathir