Home | 簡體中文 | 繁體中文 | 雜文 | 知乎專欄 | Github | OSChina 博客 | 雲社區 | 雲棲社區 | Facebook | Linkedin | 視頻教程 | 打賞(Donations) | About
知乎專欄多維度架構 | 微信號 netkiller-ebook | QQ群:128659835 請註明“讀者”

第 35 章 UI Layout

目錄

35.1. 切換UI
35.1.1.
35.1.2. startActivity()
35.1.3. Activity 間數據傳遞
35.2. Button
35.2.1. 啟用禁用
35.2.2. 實現 OnClickListener 介面
35.3. ListView
35.3.1. Array
35.3.2. List
35.3.3. setOnItemClickListener()
35.3.4. 用介面方法實現
35.4. Switch
35.5. GardView
35.6. GridView
35.7. ProgressBar
35.8. ImageView
35.9. Fragment
35.10. Dialog
35.11. Menu

35.1. 切換UI

35.1.1. 

			
setContentView(R.layout.view);			
			
			

35.1.2. startActivity()

		
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
     <application android:label="Test">
 
		...
		...
        <activity android:name=".WriteActivity"></activity>

    </application>

</manifest>		
		
			

		
		Button button = (Button) findViewById(R.id.writeButton);

        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                setContentView(R.layout.activity_write);
                Intent intent = new Intent(MainActivity.this,WriteActivity.class);
                startActivity(intent);
            }
        });		
		
			

35.1.3. Activity 間數據傳遞

		
Intent it = new Intent(Activity.Main.this, Activity2.class);
Bundle bundle=new Bundle();
bundle.putString("name", "This is from MainActivity!");
it.putExtras(bundle);
startActivity(it);		
		
			

獲取數據

		
Bundle bundle=getIntent().getExtras();
String name=bundle.getString("name");