リスト内のアイテムがクリックされたときに特定のIDを取得しようとしています。
+ id / nameの値を取得するにはどうすればよいですか?以下に示すアラートダイアログアッシュで使用したい。
私は現在、リストアイテムがクリックされた瞬間に「名前」が表示される単純なトーストを使用しています
これが私のリストアイテムのxmlコードです:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/image" android:textSize="20dip"
android:layout_marginLeft="10dip"/>
<ImageView
android:id="@+id/image"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_centerHorizontal="true"
android:src="@drawable/stub" android:scaleType="centerCrop"/>
<TextView
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/image"
android:textSize="20dip" android:layout_marginLeft="10dip"/>
</RelativeLayout>
アラートダイアログコード:
list.setOnItemClickListener(new OnItemClickListener(){
String artistname = "get +id/name here";
String items[] = {"Youtube", "Soundcloud"};
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
AlertDialog.Builder builder = new
AlertDialog.Builder(JsonActivity.this);
builder.setTitle(artistname);
builder.setItems(items, new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog alert = builder.create();
alert.show();
}});
}