Activity 設定介面時 - Android

Annie avatar
By Annie
at 2014-07-23T17:42

Table of Contents


我使用的開發環境是 google 開發網站的 Bundle Eclips ADT

@SuppressLint({ "InlinedApi", "NewApi" }) public class Ch5_5_6Activity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_ch5_5_6);

TextView lb101= new TextView(this);
lb101.setText("XXX");
lb101.setTextSize(20);
lb101.setGravity(Gravity.CENTER);

TextView lb102= new TextView(this);
lb102.setText("XXX2");
lb102.setTextSize(20);
lb102.setGravity(Gravity.LEFT);

//建立 LinearLayout 物件
LinearLayout ll=new LinearLayout(this);
//指定版面配置的方向和寬和高
ll.setOrientation(LinearLayout.VERTICAL);
ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
ll.addView(lb101);
ll.addView(lb102);
setContentView(ll);

if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}

run as application ,要跳出activity時出現此activity stop的訊息,我看了
程式碼,是在一開始的setContentView(R.layout.activity_ch5_5_6)出了錯誤
因為我把它註解掉了,可是我後面有設定 setContentView(ll);阿,整個範例
是照著課本打的,請問我這哪邊有錯誤阿..?謝謝。

--
Tags: Android

All Comments

Madame avatar
By Madame
at 2014-07-27T06:20
setContextView 要擺在前面
Margaret avatar
By Margaret
at 2014-07-31T04:20
不然你的lb101 lb102 findView 會失敗
Lydia avatar
By Lydia
at 2014-08-04T09:27
我走錯版嗎XDDDDDD
Oliver avatar
By Oliver
at 2014-08-06T05:25
建議你去 AndroidDev版 問問
Hardy avatar
By Hardy
at 2014-08-08T20:14
你應該只是沒有clean...
John avatar
By John
at 2014-08-13T06:20
把最後面的IF拿掉就可以了
Mia avatar
By Mia
at 2014-08-17T08:54
setContextView擺前面

影片合併App

Rachel avatar
By Rachel
at 2014-07-23T17:40
想請問一下各位板友 目前Google Play商店有哪些 and#34;簡單的影片剪接Appand#34; 附費的或免費的都可以 先說明一下我的需求 and#34;只要可以把兩個影片合併在一起,然後可以選轉場效果and#34; 目前有用過了video show、小影、Magisto Magi ...

HTC 816 如何選取多個相片刪除?

Blanche avatar
By Blanche
at 2014-07-23T16:38
舍妹的手機是 HTC desire 816 手機的內建APP--相片集 似乎照片只能一張一張刪 我的NOTE2 可以在相片瀏覽時直接長按其中一張,然後勾選要刪的 一起刪除 請問HTC 816 選取多個相片的功能躲在哪邊? 謝謝解答! - ...

刷官方recovery後無法充電

Zenobia avatar
By Zenobia
at 2014-07-23T15:50
各位大大好: 小弟今天手殘將網路上官方recovery 刷入HTC J 結果插電源也無法直接充電,插到桌機會顯示集線器電源爆衝. 想請問這樣還有辦法直接從手機刷入原來的recovery嗎? 或是有其他救援方式...感謝了!! - ...

請推薦行事曆app

Zanna avatar
By Zanna
at 2014-07-23T15:02
如題 現在有哪個行事曆app比較好用? 有沒有可以跟google evernote等連動的 如果還能隨手記事的那更好 好像有個叫做Amazingnote 很強大 但是好像沒中文版 請問大家有什麼好推薦 謝謝 - ...

3G版蝴蝶S Sense6.0的OTA包

Necoo avatar
By Necoo
at 2014-07-23T15:02
https://mega.co.nz/#!chBgEQYB!gXd4rdr2rfzwBfKWWvfs-Rqbkl1wO0fOK5MGpRnQZjc 有鑑於現在採取批次更新 可能有很多板友無法收到OTA 故分享OTA包給各位 只要放進SD卡後用原廠recovery刷入即可 實測OK~ 只能從4.4.2 se ...