Android : How to Pass the previous Activity Intent into a Listview

Viewed 53

I have Two Activity ( Activity A, Activity B) In Activity A i have a EditText,Button and Image View And in Activity B i have a Listview and the listView View Contain CustomXml with ImageView,TextView,and Another TextView

in Activity A, i enter List Name in Edit Text (Ex : Apple) and i Chose One Image ina GridView (Ex an Apple Image )

and i pass Both the Edittext and ImageView to a new Activity Where i want to Display Those names in ListView (Apple and Apple Image) How to DO that

enter image description here

i want to display something like this ( i get the Grocery List and Image From the Previous Activity and i want to display in ListView( in listview i extra add the items Count TEXTVIEW)

firstActivity.Java

 done.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                String itemname = listname.getText().toString();
                if (!TextUtils.isEmpty(listname.getText().toString())) {

                    startActivity(new Intent(getContext(), CheckslateHome.class).putExtra("data", itemname).putExtra("image", imageRes));
                    dismiss();
                } else {
                    Toast.makeText(getContext(), "List Name not Empty ", Toast.LENGTH_SHORT).show();
                }

            }

        });

Second Activity public class CheckslateHome extends AppCompatActivity {

TextView listcounts;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_checkslate_home);


    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {

       String itemName= bundle.getString("data");
       Int ItemImage = bundle.getString("Image");

**//How to Pass these Intents into the Custom ListView** 

    }


    listcounts = findViewById(R.id.list_count);
    ListView listView = findViewById(R.id.list1);

    CustomAdpter customAdapter = new CustomAdpter();
    listView.setAdapter(customAdapter);

   
}

public class CustomAdpter extends BaseAdapter {


   
    private Context context;
    private LayoutInflater layoutInflater;


    @Override
    public int getCount() {
      
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        if (view == null) {
            view = layoutInflater.inflate(R.layout.rowlayout, viewGroup, false);

        }


        ImageView imageicons = view.findViewById(R.id.image_list);
        TextView listnames = view.findViewById(R.id.list_name);

       


        return view;
    }
}
1 Answers

I Highly suggest using a combination of Fragments and navigation, in this way you can easily navigate through your app and send values between fragments using safe-args plugin

but if you persist on using activity, you should use startActivityForResult to call second activity.

Related