android - How do I get the ID of the item of row (each row has 3 items) from a ListView, which contains a clickable items (imagebuttons)? -


i read many articles problem in stackoverflow didn't solve problem. have listview have rows, each row has 3 imagebuttons, when click @ imagebutton code in "setonitemclicklistener" doesn't work.

i need item(imagebutton) in rows clicked. in listview many rows.

i hear simplecursoradapter, fragmentlist, cursorloader, my min required sdk 10.

in code used 6 images going use more images(100).

my java code :

package foxstrot.ghp;  import android.app.activity; import android.content.intent; import android.os.bundle; import android.util.log; import android.view.view; import android.widget.adapterview; import android.widget.listview; import android.widget.simpleadapter; import java.util.arraylist; import java.util.hashmap; import java.util.map;  public class images extends  activity {      int[] images = {r.raw.a2, r.raw.a3, r.raw.im2, r.raw.a4, r.raw.a5, r.raw.im6,};      listview lv;      intent = new intent(this, king.class);      final string log_tag = "l";       @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.images);            lv = (listview) findviewbyid(r.id.lv);          arraylist<map <string, object>> data = new arraylist<map<string, object>>(images.length);         map<string, object> m;          for(int = 0; < images.length; i++){               m = new hashmap<string, object>();             m.put("image1", images[i]);             m.put("image2", images[i+1]);             m.put("image3", images[i+2]);             = + 2;             data.add(m);          }          string[] = {"image1","image2","image3"};         int[] = {r.id.ib1, r.id.ib2, r.id.ib3};          simpleadapter sadapter = new simpleadapter(this, data, r.layout.a_, from, to);          lv.setadapter(sadapter);           lv.setonitemclicklistener(new adapterview.onitemclicklistener() {             @override             public void onitemclick(adapterview<?> parent, view view, int position, long id) {                  i.putextra("id", id);                 startactivity(i);                 log.d(log_tag, "itemclick: position = " + position + ", id = "                         + id);             }         });           }             } 

my xml code (container used in adapter)

<?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="125dp"     >            <imagebutton             android:layout_width="fill_parent"             android:layout_height="fill_parent"             android:id="@+id/ib1"             android:layout_weight="1"             android:scaletype="fitxy"              />          <imagebutton             android:layout_width="fill_parent"             android:layout_height="fill_parent"             android:id="@+id/ib2"             android:layout_weight="1"             android:scaletype="fitxy"             />          <imagebutton             android:layout_width="fill_parent"             android:layout_height="fill_parent"             android:id="@+id/ib3"             android:layout_weight="1"             android:scaletype="fitxy"             />    </linearlayout> 

setonitemclicklistener() used detect clicks on list items (rows) not on specific buttons may have on items (rows).

for each button of row on xml need add onclick attribute function handle click: android:onclick="myfunction".

the on activity have create function:

public void myfunction(view v) {...}

if need pass specific info row clicked can add tag on button's view on adapter's getview() method. more information on check here: how row id of row listview, contains clickable item?


Comments

Popular posts from this blog

How to run C# code using mono without Xamarin in Android? -

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -