Search code examples
androidlistviewandroid-intentandroid-activity

Android: How to edit my ListView in another activity and return the edited result to the ListView


So I have a listview in my activity1 class, what i want to do is:

Click on an item in the listview, which will open activity2 class, with 2 edit texts with the values from the clicked item in the listview, like name and age strings, I want to edit those values/strings in my activity2 class [by changing the edit texts], and send the edited values back to my listview in activity1 class, and show the edited values in my listview [for example show the name] instead of showing the old value/string that was in the listview before the edit.

I have tried many different ways, and I couldn't accomplish the goal, I would love if any of you could help me.

Thank you,


Solution

  • You can transfer your selected items data to your second activity like this code below

    Intent i = new Intent(MainActivity.this,ReportActivity.class);
                i.putExtra("MainDate", MainDate.getText().toString());
    

    and in your second activity you have to get this data's and then manipulate them

    Intent intent = getIntent();
        MainDate = intent.getExtras().getString("MainDate");
    

    then send back your manipulated data's to your first Activity just like before then update your list adapter

    you can have data of your selected item in your first activity list by this code which lies on yourList.setOnItemClickListener

    Cursor Getdata = (Cursor)YourList.getItemAtPosition(position);
    String Yourcolumnstring = Getdata.getString(Getdata.getColumnIndex("yourcolumnindex")) ;