-5

add expense item

expense history

Input the form in image 1 and click the OK button, pass data from image 1 to image 2. How to add item from one activity to expense history (another activity)?

ghdbs1254
  • 11
  • 4
  • Intent i = new Intent(this, ActivityTwo.class); i.putExtra("Value1", "This value one for ActivityTwo "); i.putExtra("Value2", "This value two ActivityTwo"); – 1234567 Nov 20 '15 at 14:05
  • why not use bundle http://stackoverflow.com/questions/4999991/what-is-a-bundle-in-an-android-application – Jame.Bond Nov 20 '15 at 14:11

1 Answers1

0

You need to do the following:

//in the Activity

eventsList = new ArrayList<HashMap<String, String>>();

        // selecting single ListView item
        ListView lv = getListView();

        // Lauching the Event details screen on selecting a single event
        lv.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                // getting values from selected ListItem
                String ID = ((TextView) view.findViewById(R.id.pid))
                        .getText().toString();

                Intent intent = new Intent(view.getContext(),
                        EventDetails.class);
                intent.putExtra(pid, ID);
                view.getContext().startActivity(intent);
            }
        });

Basically what you are doing is passing the id of the selected item in the listview to then the details in the fragment of that activity. Each time a different item is selected, a different details are shown. For further reference, take a look at this tutorial.

Michele La Ferla
  • 6,775
  • 11
  • 53
  • 79