[英]How can I send an image from an ImageView in one activity to an ImageButton in another activity. Android Studio
[英]Android- How to update data on another activity. Outside the one you're working on
我有一個簡單的android應用,可組織項目列表。 我仍然是初學者,因此請原諒任何疑問。
主要活動包括現有項目列表和兩個按鈕,添加項目和檢索項目。 檢索項目會從SQLite數據庫中提取所有當前項目並顯示它們。
當我添加一個項目時,它可以正常工作並向數據庫中添加一個新項目,並且當我關閉處理添加項目的活動時,該新項目不會自動出現,我必須再次檢索數據。 我希望能夠在關閉添加項目活動后立即在屏幕上看到新項目。 在主要活動中用於檢索數據庫中項目的代碼是:
MovieDBAdapter dbadapter = new MovieDBAdapter(this);
ArrayList<HashMap<String, String>> movieList = dbadapter.getMovieList();
ListAdapter adapter = new SimpleAdapter(MainActivity.this, movieList, R.layout.view_movie_entry, new String[] {"id", "title"}, new int[] {R.id.movie_Id, R.id.title});
setListAdapter(adapter);
我嘗試在其他活動中添加此代碼,但引發了錯誤,因為setListAdapter方法僅適用於擴展listActivity的類,而添加新項的類則不適用。
關於如何執行此操作的任何建議都很好。
摘要:我想立即更新活動,而不必在mainActivity類中調用單獨的方法。
使用調用addItem Activity
startActivityForResult(Intent intent, int requestCode);
一旦添加通話中的項目
setResult(resultCode)
因此,請在其他活動中實現以下內容
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
// Check which request we're responding to
// here update the list
}
因此,一旦添加項目,setReult就會調用OnActivityResult。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.