Я пытался обновить макет на вкладке, но мне не удалось:
Основная активность
package com.hello;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.*;
import android.widget.*;
import android.widget.TabHost.OnTabChangeListener;
public class HelloAndroidActivity extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, WatchActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("watch").setIndicator("Watch",
res.getDrawable(R.drawable.watch))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, SettingsActivity.class);
spec = tabHost.newTabSpec("settings").setIndicator("Settings",
res.getDrawable(R.drawable.settings))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, ResultsActivity.class);
spec = tabHost.newTabSpec("results").setIndicator("Results",
res.getDrawable(R.drawable.results))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
public void onTabChanged(String tabId) {
WatchActivity s = new WatchActivity();
s.setBoatsinWatch();
}
});
tabHost.setCurrentTab(0);
}
}
Просмотр активности:
public class WatchActivity extends Activity {
List<String> boat_names = new ArrayList<String>();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.watch);
}
public void setBoatsinWatch() {
//setContentView(R.layout.watch);
LinearLayout ll = (LinearLayout) findViewById(R.id.boats);
ll.removeAllViews();
int j;
SettingsActivity s = new SettingsActivity();
s.initBoatNames();
boat_names = s.getBoats();
for (j=1;j<boat_names.size();j++) {
LinearLayout bl = new LinearLayout(this);
bl.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
bl.setOrientation(LinearLayout.HORIZONTAL);
Button b = new Button(this);
b.setText(boat_names.get(j));
b.setWidth(200);
b.setPadding(10, 10, 10, 10);
TextView tv = new TextView(this);
tv.setTextSize(20);
tv.setText("0");
tv.setTextColor(Color.BLACK);
tv.setPadding(50, 0, 50, 0);
ImageButton ib = new ImageButton(this);
ib.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
ib.setBackgroundResource(R.drawable.finish);
bl.addView(b);
bl.addView(tv);
bl.addView(ib);
ll.addView(bl);
}
}
Просмотр.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF" android:weightSum="2">
<TextView android:id="@+id/textView1" android:text="" android:layout_width="wrap_content" android:layout_height="30dp"></TextView>
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/boats" android:orientation="vertical">
</LinearLayout>
</LinearLayout>
Спасибо!Питер