Display edited data in listview in android
<p>I had been trying to update my edited records in the listview. When user press on the selected listview, it will go to another page to allow for editing of information. However, when the user go back to the listview, data are still not change. How do i display the edited data in the listview?</p>

<pre><code>public class NewRecord extends AppCompatActivity {
    Context context = this;
    public RecordsDataSource recordsdatasource;
    String textInEditText;
    ArrayAdapter&lt;Records&gt; RecordAdapter;
    List&lt;Records&gt; records;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_record);


        recordsdatasource = new RecordsDataSource(this);
        recordsdatasource.open();

        final EditText EmployeeName = (EditText) findViewById(R.id.EmployeeName);
        EmployeeName.setText(recordsdatasource.getFirst().getEmployeeName());
        final EditText BirthDate = (EditText) findViewById(R.id.BirthDate);
        BirthDate.setText(recordsdatasource.getFirst().getBirthDate());
        final EditText Address = (EditText) findViewById(R.id.Address);
        Address.setText(recordsdatasource.getFirst().getAddress());
        final EditText Phone = (EditText) findViewById(R.id.Phone);
        Phone.setText(recordsdatasource.getFirst().getPhone());
        final EditText DutyType = (EditText) findViewById(R.id.DutyType);
        DutyType.setText(recordsdatasource.getFirst().getType());
        final EditText BankNo = (EditText) findViewById(R.id.BankNo);
        BankNo.setText(recordsdatasource.getFirst().getBankNo());

        Button Button4 = (Button) findViewById(R.id.button4);
        Button4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder a_builder = new AlertDialog.Builder(NewRecord.this);
                a_builder.setMessage("Confirm save?")
                        .setCancelable(false)
                        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Records newRecord = new Records();
                                newRecord.setEmployeeName(EmployeeName.getText().toString());
                                newRecord.setBirthDate(BirthDate.getText().toString());
                                newRecord.setAddress(Address.getText().toString());
                                newRecord.setPhone(Phone.getText().toString());
                                newRecord.setType(DutyType.getText().toString());
                                newRecord.setBankNo(BankNo.getText().toString());
                                createRecord(newRecord);
                            }
                        })
                        .setNegativeButton("No", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                        });
                AlertDialog alert = a_builder.create();
                alert.setTitle(Html.fromHtml("&lt;font color='#08ae9e'&gt;Confirmation&lt;/font&gt;"));
                alert.show();
            }
        });

    Button button9 = (Button) findViewById(R.id.button9);
    button9.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder a_builder = new AlertDialog.Builder(NewRecord.this);
            a_builder.setMessage("Confirm save?")
                    .setCancelable(false)
                    .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Records newRecord = new Records();
                            newRecord.setId(1);
                            newRecord.setEmployeeName(EmployeeName.getText().toString());
                            newRecord.setBirthDate(BirthDate.getText().toString());
                            newRecord.setAddress(Address.getText().toString());
                            newRecord.setPhone(Phone.getText().toString());
                            newRecord.setType(DutyType.getText().toString());
                            newRecord.setBankNo(BankNo.getText().toString());
                            updateRecord(newRecord);
                            Intent returnIntent = new Intent();
                            setResult(RESULT_OK, returnIntent);
                            finish();

                        }
                    })
                    .setNegativeButton("No", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });
            AlertDialog alert = a_builder.create();
            alert.setTitle(Html.fromHtml("&lt;font color='#08ae9e'&gt;Confirmation&lt;/font&gt;"));
            alert.show();

        }
    });
}





    public static void showToast(Context context, String text) {
        Toast.makeText(context, text, Toast.LENGTH_LONG).show();
    }

    private void createRecord (Records record) {
        recordsdatasource.createRecord(record);
        showToast(getApplicationContext(), "Record added");
    }

    private void updateRecord (Records record) {
        recordsdatasource.updateRecord(record);
        showToast(getApplicationContext(), "Record updated");
    }




}


Main Page

public class Record extends ListActivity {

    public Button NewButton;
    public RecordsDataSource Recordsdatasource;
    ArrayAdapter&lt;Records&gt; RecordAdapter;
    List&lt;Records&gt; records;
    ListView listView;
    Records selectedRecord;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_record);
        Addrecords();


        //Referencing the Database
        Recordsdatasource = new RecordsDataSource(this);
        Recordsdatasource.open();

        //set the listView to use the custom List Adapter
        records = (List&lt;Records&gt;) Recordsdatasource.getAll();
        RecordAdapter = new RecordAdapter(this, 0, (ArrayList&lt;Records&gt;) records);
        listView = (ListView) findViewById(android.R.id.list);
        listView.setAdapter(RecordAdapter);


        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                selectedRecord = records.get(position);
                AlertDialog.Builder a_builder = new AlertDialog.Builder(Record.this);
                a_builder.setMessage("Are you sure you want to edit?")
                        .setCancelable(false)
                        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Intent l = new Intent(Record.this, NewRecord.class);
                                startActivity(l);


                            }
                        })
                        .setNegativeButton("No", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                        });
                AlertDialog alert = a_builder.create();
                alert.setTitle(Html.fromHtml("&lt;font color='#08ae9e'&gt;Information&lt;/font&gt;"));
                alert.show();
                updateItem(selectedRecord);

            }
        });


        listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {

                selectedRecord = records.get(position);
                AlertDialog.Builder a_builder = new AlertDialog.Builder(Record.this);
                a_builder.setMessage("Are you sure you want to delete?")
                        .setCancelable(false)
                        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                deleteItem(selectedRecord);
                            }
                        })
                        .setNegativeButton("No", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                        });
                AlertDialog alert = a_builder.create();
                alert.setTitle(Html.fromHtml("&lt;font color='#08ae9e'&gt;Alert!!&lt;/font&gt;"));
                alert.show();
                return true;
            }
        });
        return;
    }


    public void Addrecords() {
        NewButton = (Button) findViewById(R.id.NewButton);
        NewButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent addrecords = new Intent(Record.this, NewRecord.class);
                startActivity(addrecords);
            }
        });
    }


    public static void showToast(Context context, String text) {
        Toast.makeText(context, text, Toast.LENGTH_LONG).show();
    }

    private void deleteItem(Records selectedRecord) {
        Recordsdatasource.removeRecords(selectedRecord);
        showToast(this, "Record deleted");
        RecordAdapter.notifyDataSetChanged();
        RecordAdapter.notifyDataSetInvalidated();
        refreshDisplay();
    }

    private void updateItem(Records selectedRecord) {
        Recordsdatasource.updateRecord(selectedRecord);
        RecordAdapter.notifyDataSetChanged();
        refreshDisplay();

    }


    private void refreshDisplay() {
        records = Recordsdatasource.getAll();
        RecordAdapter.clear();
        RecordAdapter.addAll(records);
    }


}
</code></pre>