0
我有延伸的ListActivity
,在onCreate
方法我設置了contentView
和撥打AsyncTask
加載數據和列表中Activity
得到填補之間進行導航,因爲我想要的問題是,當我檢查例如具體活動,想回去了listView
:我得到的onCreate
方法執行,數據再次加載和listView
滾動到頂部失去我以前的位置。 我想要實現的就像google gmail應用,例如:列表視圖一次加載並保存滾動位置。如何將數據保存在一個ListView和滾動的位置,同時活動
我看了這麼多在這裏,我嘗試了許多解決方案,但沒有工作。
實現此方案的最佳方法是什麼?
我的活動:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
new LoadEvents().execute();
}
我的AsyncTask:
class LoadEvents extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Home.this);
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
protected String doInBackground(String... args) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONObject json = jParser.makeHttpRequest(AgendaIConstantes.URL_EVENTS, "GET", params);
......Processing
eventList.add(map);
}
} else {
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
pDialog.dismiss();
runOnUiThread(new Runnable() {
public void run() {
ListAdapter adapterRes = getListAdapter();
if(adapterRes == null){
ListAdapter adapter = new SimpleAdapter(Home.this, eventList,R.layout.list_item,
new String[] { .....},
new int[] { .....});
setListAdapter(adapter);
}
}
});
}
你究竟試過了什麼?在這裏發佈你的代碼可能是值得的(它的相關部分)。當你回到只有暫停的'Activity'時,'onCreate'不應該被執行AFAIK,只有'onResume',所以你可能在'Activity'的生命週期中出現錯誤。 –