Refresh ListView after updating in another Activity

前端 未结 3 397
渐次进展
渐次进展 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:07

    1) Get reference ListView

    mListView = (ListView)findViewById(R.id.auto_listview);
    

    2) Create adapter One more time with changed values

    MyAdapter myAdapter = new MyAdapter(getApplicationContext(), 
                                        R.layout.locations_list_item_layout,dataArray;
    mListView.setAdapter(myAdapter);
    
    setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    
                    public void onItemSelected(AdapterView<?> adapterView,
                            View view, int i, long l) {
    
    myAdapter = new MyAdapter(getApplicationContext(), 
        //pass changed values vlues array                               R.layout.locations_list_item_layout,dataArray;
    mListView.setAdapter(myAdapter);
    
    }
    
                    public void onNothingSelected(AdapterView<?> arg0) {
                        // TODO Auto-generated method stub
    
                    }
                });
    
    0 讨论(0)
  • 2021-01-05 18:08

    Declare fulllist as Globle Variable and used static arraylist .

    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题