android - I want to start a new activity when I click on a listview item -


i set onitemclicklistener crashes when click on 1 of list item. want know if can done

here code

update:

 public class inbox extends listactivity {      private static string[] numbers;     private static string[] content;     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.inbox_list);         dictionaryopenhelper helper = new dictionaryopenhelper(this,"mytable", null, 2);         sqlitedatabase database  = helper.getreadabledatabase();         cursor c = database.rawquery("select * mytable", null);          numbers = new string[c.getcount()];              content = new string[c.getcount()];             c.movetofirst();             int count = 0;             do{                 numbers[count] = c.getstring(c.getcolumnindex("phonenumber"));                 content[count] = c.getstring(c.getcolumnindex("message"));                 count++;             }             while(c.movetonext());              database.close();         setlistadapter(new arrayadapter<string>(this,                 android.r.layout.simple_list_item_1,                 numbers));     this.getlistview().setonitemclicklistener(listener);         }     private onitemclicklistener listener = new onitemclicklistener() {          @override         public void onitemclick(adapterview<?> arg0, view arg1, int arg2,                 long arg3) {             intent intent = new intent(inbox.this, contdisplay.class);             intent.putextra("number", numbers[arg2]);             startactivity(intent);         }     }; } 

inside oncreate:

this.getlistview().setonitemclicklistener(listener); 

arg0.getadapter().getitemid(arg2) should replaced arg2, because arg2 position of clicked list's element. think getting arrayindexoutofboundsexception because trying element of array not element's position, element's id! element's id example 100203102031230.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -