Skip to content Skip to sidebar Skip to footer

My Questions Is, How Do I Pass The List Data I Have Obtained From Json In A Fragment To An Activity?

This is my Fragment Class - Here i get the JSON array object and call the adapter class for setting it. In the corressponding XML file, i have used a card view and lsit view to dis

Solution 1:

first your model class "staff_model" implement parcelable it will help to transfer your single model item pass to other activity. Then add ItemClickListener in your listview

Solution 2:

add this into your getView function

MyViewHolder rowHolder=newMyViewHolder(convertView);
 rowHolder.setOnClickListener(newView.OnClickListener() {
                publicvoidonClick(View v) {

       //do whatever u want


                }
            });

Solution 3:

listView.setOnClickListener(new View.OnClickListener() {
                        publicvoidonClick(View v) {
         //Here you can convert your json to string 
         startActivity(new Intent(this, MainActivity.class).putExtra("myList",new Gson().toJson(list)));
     }
});

and in your receiving activity

Typetype = newTypeToken<List<String>>() {
        }.getType();
        List<String> list1=newGson().fromJson(getIntent().getStringExtra("myList"),type);

Here Specify the TypeToken .You will have the exact json that you passed in the intent.

Post a Comment for "My Questions Is, How Do I Pass The List Data I Have Obtained From Json In A Fragment To An Activity?"