android - How could I get the controls in onListItemClick from ListActivity -



android - How could I get the controls in onListItemClick from ListActivity -

i have listactivity in android project. code:

public class listactivityapp extends listactivity { /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.list); arraylist<hashmap<string, string>> listitem = new arraylist<hashmap<string, string>>(); hashmap<string, string> map; map = new hashmap<string, string>(); map.put("title", "my note"); map.put("img", string.valueof(r.drawable.paper)); listitem.add(map); map = new hashmap<string, string>(); map.put("title", "second"); map.put("img", string.valueof(r.drawable.paper)); listitem.add(map); map = new hashmap<string, string>(); map.put("title", "cos tam"); map.put("img", string.valueof(r.drawable.paper)); listitem.add(map); simpleadapter myadapter = new simpleadapter (this.getbasecontext(), listitem, r.layout.list, new string[] {"img", "title"}, new int[] {r.id.img, r.id.title}); setlistadapter(myadapter); } @override protected void onlistitemclick(listview l, view v, int position, long id) { super.onlistitemclick(l, v, position, id); string selection = getlistadapter().getitem(position).tostring(); toast.maketext(this, selection, 0).show(); }}

my list.xml:

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <listview android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <textview android:id="@android:id/empty" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="empty" />

and item.xml:

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" > <imageview android:id="@+id/img" android:layout_width="wrap_content" android:layout_height="fill_parent" /> <textview android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="fill_parent" /> </linearlayout>

the first problem (resolved) have: on emulator can see 3 textviews text "empty", when i've clicked each of them can see toast right "title". doing wrong? in project works properly. - have resolved one. in this:

simpleadapter myadapter = new simpleadapter (this.getbasecontext(), listitem, r.layout.list, new string[] {"img", "title"}, new int[] {r.id.img, r.id.title});

i should 3rd argument utilize r.layout.item, not r.layout.list.

the sec problem: how can object of list item in onlistitemclick(..) method? have of course of study position , id. l.getitematposition(position) getlistadapter().getitem(position) these methods homecoming item (in case img , title). how can illustration alter text in textview or set imageview invisible in onlistitemclick(..)?

to textview , imageview clicked item, utilize view, v, given in onclick() event , following:

textview tv = (textview)v.findviewbyid(r.id.textview); tv.settext("example text"); imageview image = (imageview)v.findviewbyid(r.id.image); image.setvisibility(imageview.invisible);

android android-listview

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -