Friday, 15 August 2014

Get an id value from list item with multiple ids in android -



Get an id value from list item with multiple ids in android -

i trying retrieve id when item in list clicked on.

how can retrieve value +id/name? want utilize in alert dialog ash shown below.

i'm working simple toast shows "name" @ moment when list item clicked on

here xml code list item:

<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>

alert dialog code:

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(); }}); }

try this

public void onitemclick(adapterview<?> parent, view view, int position, long id) { //name of artist... string name=((textview)view.findviewbyid(r.id.name)).gettext(); }

i think want...i hope help you

android list

No comments:

Post a Comment