google maps - Android OnItemCLickListener not working in listview -


i new android programming.i developing app in when user clicks on listview item should go google maps app , display pin address on map. when click on item nothing happens. following display activity.

public class displayactivity extends activity implements onitemclicklistener{  listview listview; private string tag_name;  public list<nameaddress> nameaddresslist; @override protected void oncreate(bundle savedinstancestate) {      super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_display);      listview = (listview) findviewbyid(r.id.list);      intent intent = getintent();     if(intent!= null)     {         tag_name = intent.getstringextra("dashitemname");         settitle("list of " +tag_name+ " addresses");     }      nameaddresslist = null;     try {             xmldomparserhandler parser = new xmldomparserhandler(tag_name);         nameaddresslist = parser.parsexml(getassets().open("data.xml"));         arrayadapter<nameaddress> adapter =             new arrayadapter<nameaddress>(this,r.layout.list_item, nameaddresslist);         listview.setadapter(adapter);      } catch (ioexception e) {         e.printstacktrace();     } }  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.display, menu);     return true; }   @override public void onitemclick(adapterview<?> parent, view view, int position, long id) {     // build intent     string address = nameaddresslist.get(position).tostring();     address = "geo:0,0?q=" + address;     string query = urlencoder.encode(address, "utf-8");     uri location = uri.parse(query);     intent mapintent = new intent(intent.action_view, location;     mapintent.setclassname("com.google.android.apps.maps", "com.google.android.maps.mapsactivity");      // verify resolves     packagemanager packagemanager = getpackagemanager();     list<resolveinfo> activities = packagemanager.queryintentactivities(mapintent, 0);     boolean isintentsafe = activities.size() > 0;      // start activity if it's safe     if (isintentsafe) {         startactivity(mapintent);     }     else     {         toast.maketext(this, "please install google maps app", toast.length_long).show();     }  }   } 

please suggest me way solve problem.

please suggest me way solve problem.

it doesn't work because forgot assign listener listview:

@override protected void oncreate(bundle savedinstancestate) {      super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_display);      listview = (listview) findviewbyid(r.id.list);     listview.setonitemclicklistener(this);      ... } 

now, work you.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -