編輯:高級開發
1.通過intent來傳遞:
A.傳字符等:activity1中設置:
Java代碼
String text = "hello";
Intent intent1 = new Intent(ActivityMain.this, Activity2.class);
intent1.putExtra("activity1", text);
startActivity(intent1 );
String text = "hello";
Intent intent1 = new Intent(ActivityMain.this, Activity2.class);
intent1.putExtra("activity1", text);
startActivity(intent1 );
B.傳對象,對象要實例化,繼承Serializable
Java代碼
Bundle mbundle=new Bundle(); mbundle.putSerializable("user",userList.get(position));
Intent in =new Intent (getApplicationContext(), activity2.class);
in.putExtras(mbundle);
startActivity(in);
Bundle mbundle=new Bundle(); mbundle.putSerializable("user",userList.get(position));
Intent in =new Intent (getApplicationContext(), activity2.class);
in.putExtras(mbundle);
startActivity(in);
activity2中接收:
A:接收
Java代碼
Bundle extras = getIntent().getExtras();
if (extras != null) {
textvIEw.setText(extras.getString("activity1"));
}
Bundle extras = getIntent().getExtras();
if (extras != null) {
textvIEw.setText(extras.getString("activity1"));
}
B.接收
Java代碼
Bundle bundel = getIntent().getExtras();
user= (User) bundel.get("user");
Bundle bundel = getIntent().getExtras();
user= (User) bundel.get("user");
2.SharedPreferences
我在activity1中設置的如下:
Java代碼
SharedPreferences sp =getSharedPreferences("textinfo",0);
Editor editor=sp.edit();
String text = "hello";
editor.putString("text", text);
editor.commit();
接上頁
Intent i = new Intent(getApplicationContext(),activity2.class);
startActivity(i);
SharedPreferences sp =getSharedPreferences("textinfo",0);
Editor editor=sp.edit();
String text = "hello";
editor.putString("text", text);
editor.commit();
Intent i = new Intent(getApplicationContext(),activity2.class);
startActivity(i);
跳轉到Message的activity,獲取內容如下
Java代碼
SharedPreferences share=getSharedPreferences("textinfo",0);
String text =share.getString("text", null);
msgtextvIEw.setText(text);
項目要用到一個listvIEw,要求是可以顯示圖片,後面還有有復選框。先新建一個MyAdapter類,繼承自BaseAdapter。在MyAdapter中實現對數據的綁
理解布局對於良好的android程序設計非常重要。在這個教程裡,你將學到相對布局的所有知識,相對布局用於將用戶界面控件或小工具相對於其它控件或它們的父級布局組織在屏幕上
報告中寫道:“android是首款受到強力消費品牌青睐的Linux操作系統,而他背後的這只強力推手則是谷歌。”報告並承認Android仍然處在不成熟的發展階段,不過他們
盡管蘋果聯合創始人承認:android將取得最終勝利,不過很多人認為過於開放的環境依然不利於android,無差異的應用體驗正在制約Android超過iPhone。日前