Refresh ListView after updating in another Activity

前端 未结 3 421
渐次进展
渐次进展 2021-01-05 17:43

I have two simple Activities - Activity1: ListView from an Array Activity2: EditText for editing the clicked row in Activity1

When I edit the value in Activity2 and

3条回答
  •  轮回少年
    2021-01-05 18:10

    On clicking the item in your first Activity, start your second Activity with startActivityForResult()

    And then in Second Activity, after entering in EditText, probably there is a button. And in onClick of that button call,

    intent.putExtra("edittextvalue", findViewById(R.id.edittext).getText().toString());
    setResult(RESULT_OK, intent);
    finish();
    

    Now you come back to your first Activity and here you have to implement onActivityResult() callback. You can extract data from that intent's extras and set that respective item in your array and call notifyDataSetChanged().

    This is ideally how you should be doing it.

    If you want more info on how to use startActivityForResult() try this link - http://manisivapuram.blogspot.in/2011/06/how-to-use-startactivityforresult.html

提交回复
热议问题