android - Assigning different tasks to different list items -


i have list item , has 3 items in it. want following: when clicked 1 of them, redirected google, , when clicked other, go facebook , on. in code, when click of 3 list items, go same address:google. how can assign different links different list items? here code.

public class mainactivity extends activity {  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      // listimizde kaç tane eleman olduğunu bulmak için bunu kullanıyoruz     listview listview = (listview) findviewbyid(r.id.linklist);      string[] links = new string[] { "http://www.facebook.com",             "http://www.twitter.com", "http://www.hurriyet.com.tr" };      // arrayadapter, bu listviewin nasıl görüneceğini belirtir. ilk argument     // this, yani bu list     // 2. argument list viewin şekli, yani simple dropdown şeklinde olsun,     // 3. argument de links     arrayadapter<string> adapter = new arrayadapter<string>(this,             android.r.layout.simple_list_item_1, links);      listview.setadapter(adapter); // start adapter list view     listview.setonitemclicklistener(new adapterview.onitemclicklistener() {         @override         public void onitemclick(adapterview<?> adapter, view view, int pos,                 long id) {             // listener             intent myweblink = new intent(                     android.content.intent.action_view);             myweblink.setdata(uri.parse("http://www.google.com"));             startactivity(myweblink);         }     });      // or listener  } 

thank you

you can achieve on position id

switch (pos){  case 1: //go google break; case 2: //go facebook break; default: //where ever want break; } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -