android - How to make an Intent in Alertdialog clicking ListView item? -
hi,
i'm trying these steps:
1)select item(song_title) on listview
2)once item selected alertdialog has started(with list of "listen" , "download")
3)selected 1 of 2 items on alertdialog
4)create intent start activity(download file)
don't understand how implement steps 3 , 4.
here part of code itemclicklistener:
ls.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { log.d(null, ". position: " + position ); showdialog(position); } });
and part creating dialog
protected dialog oncreatedialog(int id){ alertdialog.builder adb = new alertdialog.builder(mainactivity.this); final string[] service = {"play music", "download"}; adb.settitle("choose service"); switch(id){ case 0: log.d(null, service[id] + ". position: " ); adb.setitems(service, myclicklistener); break; case 1: log.d(null, service[id] + ". position: " ); adb.setitems(service, myclicklistener); break; } return adb.create(); }
it works 2 items(songs), want alter code case when there more 2 items.
answering on question )
here code work me:
ls.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { final int selectedposition = position; final string[] service = {"play music", "download"}; alertdialog.builder adb = new alertdialog.builder(mainactivity.this); adb.settitle("choose service"); adb.setitems(service, new onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { switch(which){ case 0: intent playintent = new intent(getapplicationcontext(), playmusicactivity.class); playintent.putextra("songindex", selectedposition); log.d(null, + ". position: " + selectedposition ); break; case 1: intent downloadintent = new intent(getapplicationcontext(), downloadactivity.class); downloadintent.putextra("songindex", selectedposition); log.d(null, + ". position: " + selectedposition ); break; } } }); adb.show(); } });
Comments
Post a Comment