Home | 簡體中文 | 繁體中文 | 雜文 | 打賞(Donations) | Github | OSChina 博客 | 雲社區 | 雲棲社區 | Facebook | Linkedin | 知乎專欄 | Search | About

第 4 章 UI Layout

目錄

4.1. 切換UI
4.1.1.
4.1.2. startActivity()
4.1.3. Activity 間數據傳遞
4.2. Button
4.2.1. 啟用禁用
4.2.2. 實現 OnClickListener 介面
4.3. ListView
4.3.1. Array
4.3.2. List
4.3.3. setOnItemClickListener()
4.3.4. 用介面方法實現
4.4. Switch
4.5. GardView
4.6. GridView
4.7. ProgressBar
4.8. ImageView
4.9. Fragment
4.10. Dialog
4.11. Menu

4.1. 切換UI

4.1.1. 

			
setContentView(R.layout.view);			
			
			

4.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);
            }
        });		
		
			

4.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");