priya89
priya89

Reputation: 77

intenting values individually form Listview row containing multiple values

I want to intent values separately from each listview row containing multiple values to another activity. And fetch each value in editext seperately in another activity:

My code is:

try
            {               
                JSONArray jArray =  new JSONArray(result);
                final ArrayList <String>arrayListTitle = new ArrayList<String>();
                    for(int i=0;i<jArray.length();i++)
                    {   
                        StringBuilder s = new StringBuilder();
                        JSONArray innerJsonArray = jArray.getJSONArray(i);
                        JSONObject json_data = innerJsonArray.getJSONObject(0);                          
                         at1=json_data.getString("title");
                         at= json_data.getString("mdate");
                         at2=json_data.getString("mtime");
                         at3=json_data.getString("venue");
                         at4=json_data.getString("organiser");
                         arrayListTitle.add(at1);
                         arrayListTitle.add(at);
                         arrayListTitle.add(at2);
                         arrayListTitle.add(at3);
                         s.append("\nTitle:"+at1);
                         s.append("\ndate:"+at);
                         s.append("\nTime:"+at2);
                         s.append("\nVenue:"+at3);
                         s.append("\nOrganiser:"+at4);  
                         s.append("\n");


                         r.add(s.toString());
                    }


                l.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, r));
                l.setOnItemClickListener(new OnItemClickListener() 
                {
                    public void onItemClick(AdapterView<?> myAdapter, View myView, int myItemInt, long mylng) 
                    {
                      String selectedFromList =(String) (l.getItemAtPosition(myItemInt));

                        // Starting new intent
                        intent1 = new Intent(RequestmeetActivity.this, ConfirmmeetActivity.class);


                        intent1.putExtra("title", arrayListTitle.get(myItemInt));
                        intent1.putExtra("mdate", arrayListTitle.get(myItemInt));
                        intent1.putExtra("mtime", arrayListTitle.get(myItemInt));
                        intent1.putExtra("venue", arrayListTitle.get(myItemInt));


                        startActivity(intent1); 
                    }                 
              });
            }

My activity looks like:

enter image description here

So i want to fetch value from this list view row individually and intent those value to another activity. How can i do that. Pls hlp me i am a newbie in android.. Thanks in advance. On another activity

Bundle extras = getIntent().getExtras();
    if(extras != null){ 
      mtitle = extras.getString("title");
      stime = extras.getString("mtime");
      sdate = extras.getString("mdate");
      cvenue = extras.getString("venue");
    }

    title.setText(mtitle);
    cdate=(EditText)findViewById(R.id.editText2);
    cdate.setText(sdate);
    venue=(EditText)findViewById(R.id.editText4);
    venue.setText(cvenue);
    ctime=(EditText)findViewById(R.id.editText3);
    ctime.setText(stime);

Upvotes: 1

Views: 279

Answers (3)

Maulik
Maulik

Reputation: 3316

defind global ArrayList arrayListTitle = new ArrayList; as you define in r. and add value in it before append code in for loop. for the title arrayListTitle.add(at1);

ArrayList<String> arrayListTitle = new ArrayList<String>;

    for(int i=0;i<jArray.length();i++) {    
            StringBuilder s = new StringBuilder();
            JSONArray innerJsonArray = jArray.getJSONArray(i);
            JSONObject json_data = innerJsonArray.getJSONObject(0);
            at1=json_data.getString("title");
            at= json_data.getString("mdate");
            at2=json_data.getString("mtime");
            at3=json_data.getString("venue");
            at4=json_data.getString("organiser");
            arrayListTitle.add(at1);  // check this line I have added value of title in arraylist you can take it same as data and time etc.
            s.append("\nTitle:"+at1);
            s.append("\ndate:"+at);
            s.append("\nTime:"+at2);
            s.append("\nVenue:"+at3);
            s.append("\nOrganiser:"+at4);   
            s.append("\n");
            r.add(s.toString());
        }

for listview item click:

 l.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> myAdapter, 
                                   View myView, int myItemInt, long mylng) {
        String selectedFromList =(String) (l.getItemAtPosition(myItemInt));
        // Starting new intent
        intent1 = new Intent(RequestmeetActivity.this, 
                                                    ConfirmmeetActivity.class);
        intent1.putExtra("title",arrayListTitle.get(myItemInt)); // check this line get value from the arraylistTitle for the particular position.
        intent1.putExtra("mdate",selectedFromList);
        intent1.putExtra("uid",uid);
        startActivity(intent1); 
    }

while getting the title in the another activity: write code like:

String title;

Bundle extras = getIntent().getExtras();
if(extras != null){ 
  title = extras.getString("title"); // same for others
}

editTxt.setText(title);

Upvotes: 1

Vinay
Vinay

Reputation: 2415

As I understand, you wish to send the data of the selected rows entire data to 2nd activity and edit the same.

To do this, you better create an simple custom adapter using arrayadapter as base class.

In your adapter's getView method set the Tag with your JSON Object and you can pass the entire json object to the second activity.

Simple adapter example is here

Upvotes: 0

Ramprasad
Ramprasad

Reputation: 8071

  • Instead of using android default list item layout(android.R.layout.simple_list_item_1) use your own custom layout for List item.

  • In that list item, you can separate each Fields as each text view.

  • Then you can get each field fro your adapter.

Upvotes: 0

Related Questions