The main activity of the application is to display a list. The user clicks on something on the list which opens a edit screen. Upon fisnish, the edit screen is closed - and I want the original list to be updated with whatever hapenned on the edit screen. I save the data to a file - and I can just read it again to update the list. However I don't know where to insert the re-read code.
In the ListActivity - what method is called whe the list gets focus again?
This is my main List activity code:
Creating the view:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Inflate our UI from its XML layout description.
setContentView(R.layout.my_activity);
list=new Data_List(this); // my data reading class
list.read_data(); // reads from a file
load_dynamic_list();
}
Loading the data:
private void load_dynamic_list(){
ladapter=new
list_adapter(this,android.R.layout.simple_list_item_1,list); // the type is actually ignored // getview function in list_adapter handles everything
setListAdapter(ladapter);
this.getListView().invalidate();
}
Something was selected:
protected void onListItemClick (ListView l, View v, int position, long id){
int a;
intent = new Intent(this,Editing.class);
intent.putExtra("New_entry",0);
intent.putExtra("Entry",position);
//start the second Activity
this.startActivity(intent);
}
In the Editing function I end off like this:
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v.getId() == R.id.button_save){
do_save(); // saves to a file
// I want something like: caller.getListView().invalidate();
finish();
}
if(v.getId() == R.id.button_cancel){
finish();
}
}
What method can I override or call that will execute when the editing is done? At that point I want to read_data()
and then load_dynamic_list()
again.
You have to use AsyncTask.
Prefer URL :
http://steveliles.github.com/android_s_asynctask.html http://www.vogella.com/articles/AndroidPerformance/article.html
With example :
http://labs.makemachine.net/2010/05/android-asynctask-example/
@Override
protected void onResume() {
super.onResume();
list=new Data_List(this);
list.read_data();
load_dynamic_list(); // becuase whatever was edited needs to be reread.
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.