0

Hello guys i want to ask a question about android intent extras. I am new to Android enviroment.

i have a programm which displays some records from a database to a ListView. How can i retrieve the position of the on itemclicklistener and inn which way i can pass the name the type and the address to other activity?

Here is my code:

      public void updateJSONdata() {


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


    JSONParser jParser = new JSONParser();

    JSONObject json = jParser.getJSONFromUrl(SHOW_BARS_URL);


    try {


        barAvalaibleForUser = json.getJSONArray(TAG_POSTS);


        for (int i = 0; i < barAvalaibleForUser.length(); i++) {
            JSONObject c = barAvalaibleForUser.getJSONObject(i);

            // gets the content of each tag

            String name = c.getString(TAG_NAME);
            String address = c.getString(TAG_ADDRESS);
            String type = c.getString(TAG_TYPE);
            // creating new HashMap
            HashMap<String, String> map = new HashMap<String, String>();

            map.put(TAG_NAME, name);
            map.put(TAG_ADDRESS, address);
            map.put(TAG_TYPE, type);


            barAvalaibleForUserList.add(map);


        }

    } catch (JSONException e) {
        e.printStackTrace();
    }
}

private void updateList() {


    final ListAdapter adapter = new SimpleAdapter(this, barAvalaibleForUserList,
            R.layout.layout_list_item, new String[] { TAG_NAME, TAG_ADDRESS,
            TAG_TYPE }, new int[] { R.id.bar_name_txt, R.id.bar_address_txt,
            R.id.bar_type_txt });


    setListAdapter(adapter);


           ListView  lv = getListView();
    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                                int position, long id) {

            Intent intent = new Intent(MainActivity.this,CafeInfo.class);



            startActivity(intent);



        }
    });
}
Vasilis13
  • 51
  • 1
  • 7
  • possible duplicate of [How do I pass data between activities in Android?](http://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android) – Rami Apr 25 '15 at 00:56

1 Answers1

0

It was a starter question but if anyone has the same question the answer is:

 HashMap<String, String> map = barAvalaibleForUserList.get(position);

            Intent intent = new Intent(MainActivity.this,CafeInfo.class);

            intent.putExtra("KEY",map.get(TAG_NAME));
            intent.putExtra("KEY1",map.get(TAG_ADDRESS));
            intent.putExtra("KEY2",map.get(TAG_TYPE));
            startActivity(intent);
Vasilis13
  • 51
  • 1
  • 7