-1
私はxamarin androidの新機能です.json形式の値をとるリストビューを作成しました。リストビューのクリックした項目の名前またはIDを取得したいのですが、わかりません...ここクリック時のリストビュー項目のデータを取得
は、私のクラスは、JSON
とリストビューを移入する方法class Doctors
{
public int id;
public string Name;
public string address;
public string spec;
public string rating;
public string fee;
public Doctors(string Name, string address, string spec, string rating, string fee)
{
this.Name = Name;
this.address = address;
this.spec = spec;
this.rating = rating;
this.fee = fee;
}
}
とここに私のアダプタが
class DoctorsAdapter : BaseAdapter<Doctors>
{
private Context mContext;
private int mRowLayout;
private List<Doctors> mFriends;
public DoctorsAdapter(Context context, int rowLayout, List<Doctors> friends)
{
mContext = context;
mRowLayout = rowLayout;
mFriends = friends;
}
public override int Count
{
get { return mFriends.Count; }
}
public override Doctors this[int position]
{
get { return mFriends[position]; }
}
public override long GetItemId(int position)
{
return position;
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
View row = convertView;
if (row == null)
{
row = LayoutInflater.From(mContext).Inflate(mRowLayout, parent, false);
}
TextView name = row.FindViewById<TextView>(Resource.Id.docname);
name.Text = mFriends[position].Name;
TextView spec = row.FindViewById<TextView>(Resource.Id.docspec);
spec.Text = mFriends[position].spec;
TextView address = row.FindViewById<TextView>(Resource.Id.docadd);
address.Text = mFriends[position].address;
TextView feeetv = row.FindViewById<TextView>(Resource.Id.feetv);
feeetv.Text = mFriends[position].fee;
RatingBar doctorrating = row.FindViewById<RatingBar>(Resource.Id.docrating);
doctorrating.Rating = Int32.Parse(mFriends[position].rating);
return row;
}
}
とこのです
private void populatelistview()
{
if (jsonString == null)
{
Toast.MakeText(this, "json is null", ToastLength.Long);
}
else
{
try
{
// jsonobject = JObject.Parse(jsonString);
jsonArray = JArray.Parse(jsonString);
mDoctors = new List<Doctors>();
int count = 0;
while (count < jsonArray.Count)
{
Doctors doctor = new Doctors(jsonArray[count]["Name"].ToString(), jsonArray[count]["spec"].ToString(), jsonArray[count]["address"].ToString(), jsonArray[count]["rating"].ToString(), jsonArray[count]["fees"].ToString());
// Toast.MakeText(this, jsonArray[count]["name"].ToString(), ToastLength.Long).Show();
mDoctors.Add(doctor);
count++;
}
mListView = FindViewById<ListView>(Resource.Id.docview);
mAdapter = new DoctorsAdapter(this, Resource.Layout.ticket_result, mDoctors);
mListView.Adapter = mAdapter;
mListView.ItemClick += MListView_ItemClick;
}
catch (System.Exception exception)
{
Toast.MakeText(this, exception.ToString(), ToastLength.Long);
}
}
[アンドロイドリストビューの選択可能な複製](http://stackoverflow.com/questions/4508979/android-listview-get-selected-item) –