java - How to list all events on list view with database? -
the program/apk need list titles , when run apk close please me dont know happens really
package com.eu.agendamarinhagrande; import android.annotation.targetapi; import android.app.progressdialog; import android.content.intent; import android.os.asynctask; import android.os.build; import android.support.v7.app.actionbar; import android.support.v7.app.actionbaractivity; import android.os.bundle; import android.util.log; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.adapterview; import android.widget.listadapter; import android.widget.listview; import android.widget.simpleadapter; import android.widget.textview; import com.eu.agendamarinhagrande.jsonparser; import com.eu.agendamarinhagrande.r; import org.apache.http.namevaluepair; import org.json.jsonarray; import org.json.jsonexception; import org.json.jsonobject; import java.util.arraylist; import java.util.hashmap; import java.util.list; public class mainactivity extends actionbaractivity { // progress dialog private progressdialog pdialog; // creating json parser object jsonparser jparser = new jsonparser(); arraylist<hashmap<string, string>> empresalist; // url products list private static string url_all_empresas = "http://www.grifin.pt/projectoamg/conexao.php"; // json node names private static final string tag_titulo = "titulo"; // products jsonarray string resultado = null; listview lista; @targetapi(build.version_codes.honeycomb) @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); // hashmap para el listview empresalist = new arraylist<hashmap<string, string>>(); loadallproducts loadallproducts = new loadallproducts(); // cargar los productos en el background thread lista = (listview) findviewbyid(r.id.agenda); loadallproducts.execute(string.valueof(lista)); actionbar actionbar = getsupportactionbar(); actionbar.setdisplayhomeasupenabled(true); }//fin oncreate class loadallproducts extends asynctask<string, string, string> { /** * antes de empezar el background thread show progress dialog */ @override protected void onpreexecute() { super.onpreexecute(); pdialog = new progressdialog(mainactivity.this); pdialog.setmessage("a carregar eventos. por favor espere..."); pdialog.setindeterminate(false); pdialog.setcancelable(false); pdialog.show(); } /** * obteniendo todos los productos */ protected string doinbackground(string... args) { // building parameters list params = new arraylist(); // getting json string url jsonobject json = jparser.makehttprequest(url_all_empresas, "get", params); stringbuilder sb = new stringbuilder(); // check log cat json reponse log.d("all products: ", url_all_empresas.tostring()); resultado = sb.tostring(); try { // checking success tag // products found // getting array of products jsonarray arrayjson = new jsonarray(resultado); (int = 0; i<arrayjson.length();i++){ // storing each json item in variable jsonobject c = arrayjson.getjsonobject(i); string titulo = c.getstring(tag_titulo); // creating new hashmap hashmap map = new hashmap(); // adding each child node hashmap key => value map.put(tag_titulo, titulo); empresalist.add(map); } } catch (jsonexception e) { e.printstacktrace(); } return null; } 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( mainactivity.this, empresalist, r.layout.single_post, new string[]{ tag_titulo }, new int[]{ r.id.single_post_tv_id }); // updating listview //setlistadapter(adapter); lista.setadapter(adapter); } }); } } }
check line in oncreate() method:
loadallproducts.execute(string.valueof(lista));
you can not string value of listview! if want value of textview in listview, add onitemclick event listview , value of textview in selected list item this:
//a variable, use methods, have value value of selected textview private string selectedvalue; @override protected void onlistitemclick(listview l, view v, int position, long id) { view view = (view)v.getparent(); textview textyouneed = (textview) view.findviewbyid(r.id.textviewid); selectedvalue = textyouneed.gettext(); }
and use variable in line told above:
loadallproducts.execute(selectedvalue);
Comments
Post a Comment