Android開發中Bundle用法 包裹資料

2021-08-26 10:27:30 字數 1018 閱讀 3833

它幫助我將資料打包傳入intent裡面,為使用這些資料提供了便利。

protected void onlistitemclick (listview l, view v, int position, long id)

super.onlistitemclick(l, v, position, id);

//獲得選中項的hashmap物件

hashmapmap=(hashmap)lv.getitematposition(position);

string type=map.get("type");

intent i=new intent(this,title.class);

bundle mbundle=new bundle();

mbundle.putstring("type", type);

i.putextras(mbundle);

startactivity(i);

**中1、例項化bundle 乙個物件,用putstring(標記,資料)來將資料匯入到bundle物件中;

2、然後將bundle物件匯入到intent物件中;

3、intent啟動另乙個activity。

從intent中讀出需要的資料:

bundle = getintent().getextras();

if(bundle!=null)

type=bundle.getstring("type");

if(type!=null)

//從資料庫依據所選型別讀出 文章的title,儲存在cur中

cur=mydbadapter.gettitle(new string);

4、bundle物件可以從activity.getintent().getextras()中返回。 可見,啟動當前activity 的intent物件是由getintent()來找到的。

5、通過bundle的getstring()方法,就可以讀出所要的資料。

這就是bundle的經典用法,包裹資料放入intent中,目的在於傳輸資料。

android開發中的

線性布局 linear layout 相對布局 relative layout 布局 table layout 網格檢視 grid view 標籤布局 tab layout 列表檢視 list view 絕對布局 absolutelayout 1.實現tab的效果必須使用tabhost控制項作為ta...

Android中Matrix開發彙總

開發中遇到一些涉及到matrix的地方,現在此歸納,便於日後查閱。通過對imageview設定matrix來實現imageview中的單指拖動和兩指縮放 核心方法 imageview.setimagematrix matrix 所以我們的重點在於去操作乙個matrix.該處主要用到的是利用matri...

Android中JNI開發(一)開發環境

android中jni開發環境 大概分4個步驟 3.配置環境 這個很簡單。找到cygwin目錄下,開啟home 使用者 bash profile檔案,新增 ndk cygdrive 你的碟符 4.現在配置就算是完成了,可以直接通過命令 ndk ndk build 來編譯android專案中的c c ...