android - Pass data from a listview to a new activity -


can me following issue:

when click on item in listview, need open new activity data listview...

here code:

public class listar_clientes extends listactivity {      private progressdialog pdialog;      // creating json parser object     jsonparser jparser = new jsonparser();      arraylist<hashmap<string, string>> productslist;      // url products list     private static string url_all_products = "http://192.168.137.100:81/androidapp/listar_clientes.php";      // json node names      private static final string tag_cliente= "clientes";     private static final string tag_nome = "nome";     private static final string tag_abv = "nome2";       // products jsonarray     jsonarray products = null;      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_listar_clientes);            // hashmap listview         productslist = new arraylist<hashmap<string, string>>();          // loading products in background thread         new loadallproducts().execute();         //  log.v("count-->",productslist.get(0).tostring());         // listview      listview list = getlistview();         // launching edit product screen //        lv.setonitemclicklistener(new adapterview.onitemclicklistener() { // // //                // starting new intent //                intent in = new intent(getapplicationcontext(), //                        list_item.class); //                // sending pid next activity //                in.putextra(tag_pid, pid); // //                // starting new activity , expecting response //                startactivityforresult(in, 100); //            } //        });        /*  listadapter adapter = new simpleadapter(                 encomendas_user.this, productslist,                 r.layout.activity_list_item, new string[] { tag_iduser,                 tag_titulo},                 new int[] { r.id.pid, r.id.name });         // updating listview         setlistadapter(adapter);*/         // on seleting single product         // launching edit product screen      }      // response edit product activity     @override     protected void onactivityresult(int requestcode, int resultcode, intent data) {         super.onactivityresult(requestcode, resultcode, data);         // if result code 100         if (resultcode == 100) {             // if result code 100 received             // means user edited/deleted product             // reload screen again             intent intent = getintent();             finish();             startactivity(intent);         }      }        /**      * background async task load product making http request      * */     class loadallproducts extends asynctask<string, string, string> {          /**          * before starting background thread show progress dialog          * */         @override         protected void onpreexecute() {             super.onpreexecute();             pdialog = new progressdialog(listar_clientes.this);             pdialog.setmessage("a carregar dados. por favor aguarde...");             pdialog.setindeterminate(false);             pdialog.setcancelable(false);             pdialog.show();         }          /**          * getting products url          * */         protected string doinbackground(string... args) {             // building parameters             list<namevaluepair> params = new arraylist<namevaluepair>();              // getting json string url             jsonobject json = jparser.makehttprequest(url_all_products, "get", params);              // check log cat json reponse             log.d("all products: ", json.tostring());              try {                 // checking success tag                 //  int success = json.getint(tag_iduser);                 //log.d("namsuccesse: ", ""+success);                 //if (success == 1) {                 // products found                 // getting array of products                 products = json.getjsonarray(tag_cliente);                  // looping through products                 (int = 0; < products.length(); i++) {                     jsonobject c = products.getjsonobject(i);                       // storing each json item in variable                     string name = c.getstring(tag_nome);                     string abv = c.getstring(tag_abv);                       log.d("name teste: ", name);                     // creating new hashmap                     hashmap<string, string> map = new hashmap<string, string>();                      // adding each child node hashmap key => value                     map.put(tag_nome, "nome:"+" "+ name);                     map.put(tag_abv,  "abreviatura:"+" "+abv);                       // if(userinfo.userid==(integer.parseint(name))){                         // adding hashlist arraylist                     productslist.add(map);                    // }                   }               /*  } else {                     // no products found                     // launch add new product activity                     //intent = new intent(getapplicationcontext(),                            // newproductactivity.class);                     // closing previous activities                     //i.addflags(intent.flag_activity_clear_top);                    // startactivity(i);                 }*/             } catch (jsonexception e) {                 e.printstacktrace();             }              return null;         }          /**          * after completing background task dismiss progress dialog          * **/         protected void onpostexecute(string file_url) {             // dismiss dialog after getting products             pdialog.dismiss();             // updating ui background thread             runonuithread(new runnable() {                 public void run() {                     /**                      * updating parsed json data listview                      * */                      listadapter adapter = new simpleadapter(                             listar_clientes.this, productslist,                             r.layout.activity_list_item_clientes, new string[] { tag_nome, tag_abv},                             new int[] { r.id.name, r.id.abv});                     // updating listview                     setlistadapter(adapter);                  }             });          }          /*private adapterview.onitemclicklistener onlistclick=new adapterview.onitemclicklistener(){               @override             public void onitemclick(adapterview<?> parent, view view, int position, long id) {                 intent = new intent(listar_clientes.this, detalhes_cliente.class);                 in.putextra(tag_nome, id_user.gettext().tostring());                 startactivity(i);             }         }*/          public void detalhes (view v){             intent = new intent(listar_clientes.this, detalhes_cliente.class);          }     } } 

here xml code:

<?xml version="1.0" encoding="utf-8"?> <scrollview     xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/scroll"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:fillviewport="false">     <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:orientation="vertical"         android:paddingbottom="5dp"         android:longclickable="true"         android:padding="10dp"         android:onclick="detalhes"         >          <!-- product id (pid) - hidden - used pass other activity -->         <textview             android:id="@+id/pid"             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:visibility="gone"             android:paddingbottom="5dp"/>          <!-- name label -->         <textview             android:id="@+id/name"             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:paddingtop="6dip"             android:paddingleft="6dip"             android:textsize="17dip"             android:textstyle="bold"             android:textcolor="#ff014cff"             android:text="nome cliente"             android:paddingbottom="5dp"/>         <textview             android:id="@+id/abv"             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:layout_below="@+id/name"             android:paddingtop="6dip"             android:paddingleft="6dip"             android:textsize="17dip"             android:textstyle="bold"             android:textcolor="#ff000000"             android:text="abreviatura" />        </relativelayout> </scrollview> 

just change method per data send.

public void detalhes (view v){     intent = new intent(listar_clientes.this, detalhes_cliente.class);     bundle mbundle = new bundle();     mbundle.putstring(key1, value1);     mbundle.putint(key2,value2);     mbundle.putstringarray(key3, value3);     mbundle.putstringarraylist(key4, value4);     ..     ....     mbundle.putint(key, value);     i.putextras(mbundle);     startactivity(i); } 

for reference can use link how data bundle , more clarity. may helpful ..thanks


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -