android - Passing String Array to another class using Intents -
actually have 2 activities namely mainactivity , listview .
want pass string array "arr" mainactivity listview ..
, activity listview show list of elements of "arr"
note: data in arr supplied database created me , , works fine .
there issue retrieving of arr in activity listview
mainactivity
package com.vivekmishra1991.database; import android.content.context; import android.content.intent; import android.database.cursor; import android.os.bundle; import android.app.activity; import android.view.menu; import android.view.view; import android.widget.arrayadapter; import android.widget.button; import android.widget.listview; import android.widget.textview; public class mainactivity extends activity { public int i; public string arr[] = new string[100]; private databasehelper databasehelper; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); // clickable textview final textview textview=(textview) findviewbyid(r.id.savedcontent); textview.setonclicklistener(new view.onclicklistener() { public void onclick(view view) { <--array(arr) retrived database--> intent intent=new intent(mainactivity.this,listview.class); intent.putextra("array",arr); startactivity(intent); } }); } // oncreate ends here }
listview
<-imports-> public class listview extends activity { listview listview; intent intent=getintent(); string[] arr=intent.getstringarrayextra("array"); public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.view_list); listview.findviewbyid(r.id.list); arrayadapter<string> adapter = new arrayadapter<string> (this,android.r.layout.simple_list_item_1,arr); listview.setadapter(adapter); }
}
you should getting extras in oncreate
'getintent().getstringarrayextra(string name)'
edit
i mistakenly wrote bundle method of passing object through intents. method wrote stores directly in intent.
Comments
Post a Comment