I want to pass the data from one class to another by passing the arraylist with id ..
listviewfirst.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Intent i= new Intent(MainActivity.this,Questionactivity.class);
// To pass data
i.putExtra("uploadarraylist", uploadarraylist);
startActivity(i);
}
Here I have pass the array list, but based on id no I want to pass the data to next activity page.
Make that arrayList as static list and then use it on another class by using declared calss reference.
If you have an arraylist such as:
ArrayList<YourClass> list;
Make your class implement the Serializable interface. After that you can add your arraylist in the putExtra() method.And in your activity:
As you have
ArrayList<HashMap<String, Object>> uploadarraylist
And you want to pass particular
HashMap
for given selected index to next Activity then,And in Questionactivity
You can pass the array list values through Bundle.
You can also use this as given below, so after that there is no need to pass via Intent:
You may declare your ArrayList as a static one like this:
By doing this you can access your ArrayList from any Activity by:
where activityname is the activity or class in which you declare the static ArrayList.
Or if you want to use intent than you can do this: