星期三, 10月 20, 2010

「Android」 TableActivity 筆記

參考: http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
在 helloViews 中的 tableActivity 中,是使用 XML的方式來實現 多個分頁。
在分頁中獨立一個 activity 做法:
1.主類別:CakeXsmS ,次要分頁類別:CsetSmsActivi,ChistoryActivi
2.向AndroidManifest.xml application裏面 註冊:

<activity android:name=".CsetSmsActivi">
<activity android:name=".ChistoryActivi">

3.開始載入:

public class CakeXsmS extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
final TabHost tabhost = getTabHost();
tabhost.addTab(tabhost.newTabSpec("tab1")
.setIndicator(this.getResources().getText(R.string.SUBMIT_SMS)
).setContent(new Intent(this,CsetSmsActivi.class)));

tabhost.addTab(tabhost.newTabSpec("tab2")
.setIndicator(this.getResources().getText(R.string.SMS_DATA))
.setContent(new Intent(this,ChistoryActivi.class)));
}
}

4.撰寫分頁的activity:

public class ChistoryActivi extends Activity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
.......MORE......
public class CsetSmsActivi extends Activity {
.......MORE......

沒有留言: