如何在使用选项卡时设置新的 xml 布局
我正在尝试创建一个具有多个活动的选项卡式界面。作为选项卡的一部分,我创建并设置了一个 xml tabhost 文件,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
这在我的 Tabs.class 文件中被调用,如下所示:
package com.system.kenetix;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
public class Tabs extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs);
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, Availability.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("Availability").setIndicator("Booking",
res.getDrawable(R.drawable.kenetix_tab_available))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, RoomsAvailable.class);
spec = tabHost.newTabSpec("Room").setIndicator("Rooms",
res.getDrawable(R.drawable.kinetix_tab_rooms))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, CustomerDetails.class);
spec = tabHost.newTabSpec("Customer").setIndicator("Customer",
res.getDrawable(R.drawable.kinetix_tab_customer))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Payment.class);
spec = tabHost.newTabSpec("Payment").setIndicator("Payment",
res.getDrawable(R.drawable.kinetix_tab_payment))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Extras.class);
spec = tabHost.newTabSpec("Extras").setIndicator("Extras",
res.getDrawable(R.drawable.kinetix_tab_extras))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
}
然后,我为每个选项卡都有单独的类和一个用于设置内容的 xml 文件(按钮、微调器等)如下所示:
package com.system.kenetix;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;
public class Availability extends Activity {
/** Called when the activity is first created. */
Intent intent = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.availability);
/*Nights Spinner*/
//Create an instance of the Number of Nights spinner
Spinner NumNightsSpinner = (Spinner) findViewById(R.id.NumAdultsSpinner);
//Create an ArrayAdapter for the Number of Nights spinner
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.NumNights_array, android.R.layout.simple_spinner_item);
//Set the adapter layout
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//Apply the adapter layout to the Number of Nights spinner
NumNightsSpinner.setAdapter(adapter);
NumNightsSpinner.setOnItemSelectedListener(new MyOnNumNightsSelectedListener());
/*Adults Spinner*/
//Create an instance of the Number of Adults spinner
Spinner NumAdultsSpinner = (Spinner) findViewById(R.id.NumAdultsSpinner);
//Create an ArrayAdapter for the Number of adults spinner
ArrayAdapter<CharSequence> adapter1 = ArrayAdapter.createFromResource(this, R.array.NumAdults_array, android.R.layout.simple_spinner_item);
//Set the adapter layout
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//Apply the adapter layout to the Number of Adults spinner
NumAdultsSpinner.setAdapter(adapter);
NumAdultsSpinner.setOnItemSelectedListener(new MyOnNumAdultsSelectedListener());
/*Children Spinner*/
//Create an instance of the Number of Children spinner
Spinner NumChildSpinner = (Spinner) findViewById(R.id.NumChildSpinner);
//Create an ArrayAdapter for the Number of Children spinner
ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(this, R.array.NumChild_array, android.R.layout.simple_spinner_item);
//Set the adapter layout
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//Apply the adapter layout to the Number of Children spinner
NumChildSpinner.setAdapter(adapter);
NumChildSpinner.setOnItemSelectedListener(new MyOnNumChildSelectedListener());
Button CheckAvailable = (Button) findViewById(R.id.CheckAvailabilityBtn);
CheckAvailable.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
intent = new Intent(v.getContext(), RoomsAvailable.class);
startActivity(intent);
}
});
}
//Listener for the selected item from the number of nights spinner
public class MyOnNumNightsSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent,View view, int pos, long id){
//If no number of nights has been selected or onCreate occurs cancel the toast
if (parent.getItemAtPosition(pos).toString().equals("0")){
Toast.makeText(parent.getContext(), "You selected " + parent.getItemAtPosition(pos).toString() + " night(s)", Toast.LENGTH_LONG).cancel();
}
//Else create a toast stating the number of nights selected
else{
Toast.makeText(parent.getContext(), "You selected " + parent.getItemAtPosition(pos).toString() + " night(s)", Toast.LENGTH_LONG).show();
}
}
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
}
//Listener for the selected item from the number of adults spinner
public class MyOnNumAdultsSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent,View view, int pos, long id){
//If no number of nights has been selected or onCreate occurs cancel the toast
if (parent.getItemAtPosition(pos).toString().equals("0")){
Toast.makeText(parent.getContext(), "You selected " + parent.getItemAtPosition(pos).toString() + " adults", Toast.LENGTH_LONG).cancel();
}
else if (parent.getItemAtPosition(pos).toString().equals("1")){
Toast.makeText(parent.getContext(), "You selected " + parent.getItemAtPosition(pos).toString() + " adult", Toast.LENGTH_LONG).cancel();
}
//Else create a toast stating the number of nights selected
else{
Toast.makeText(parent.getContext(), "You selected " + parent.getItemAtPosition(pos).toString() + " adult(s)", Toast.LENGTH_LONG).show();
}
}
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
//Do Nothing
}
}
//Listener for the selected item from the number of adults spinner
public class MyOnNumChildSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent,View view, int pos, long id){
//If no number of nights has been selected or onCreate occurs cancel the toast
if (parent.getItemAtPosition(pos).toString().equals("0")){
Toast.makeText(parent.getContext(), "You selected " + parent.getItemAtPosition(pos).toString() + " children", Toast.LENGTH_LONG).cancel();
}
else if (parent.getItemAtPosition(pos).toString().equals("1")){
Toast.makeText(parent.getContext(), "You selected " + parent.getItemAtPosition(pos).toString() + " child", Toast.LENGTH_LONG).show();
}
//Else create a toast stating the number of nights selected
else{
Toast.makeText(parent.getContext(), "You selected " + parent.getItemAtPosition(pos).toString() + " children", Toast.LENGTH_LONG).show();
}
}
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
//Do Nothing
}
}
}
以及与之相关的 xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1" android:background="@color/custom_theme_color"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:baselineAligned="false" android:orientation="vertical">
<TableLayout android:layout_width="wrap_content"
android:layout_alignParentLeft="true" android:layout_height="wrap_content"
android:id="@+id/tableLayout1" android:stretchColumns="1"
android:layout_weight="1">
<TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton android:src="@drawable/icon"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:id="@+id/QuickRoomSelect" android:layout_weight="1" />
<ImageButton android:src="@drawable/icon"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:id="@+id/QuickCustomerDetails" android:layout_weight="1" />
<ImageButton android:src="@drawable/icon"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:id="@+id/imageButton1" android:layout_weight="1" />
</TableRow>
</TableLayout>
<TextView android:layout_width="match_parent"
android:textColor="@color/custom_theme_text_color" android:id="@+id/availabilityLbl"
android:text="@string/AvailableLbl" android:layout_height="wrap_content"
android:layout_weight="1" />
<Button android:layout_height="wrap_content" android:id="@+id/DateFromBtn"
android:layout_width="match_parent" android:text="@string/DateFromBtn"
android:layout_weight="1" />
<TextView android:textColor="@color/custom_theme_text_color"
android:layout_height="wrap_content" android:id="@+id/NumNightsLdl"
android:text="@string/NumNightsLbl" android:layout_width="wrap_content"
android:layout_weight="1"></TextView>
<Spinner android:layout_height="wrap_content" android:id="@+id/NumAdultsSpinner"
android:layout_width="wrap_content" android:layout_weight="1"></Spinner>
<TableLayout android:layout_height="wrap_content"
android:id="@+id/tableLayout2" android:layout_width="match_parent"
android:layout_weight="1">
<TableRow android:id="@+id/tableRow3" android:layout_height="wrap_content"
android:layout_width="match_parent" android:layout_weight="1">
<TextView android:textColor="@color/custom_theme_text_color"
android:layout_height="wrap_content" android:id="@+id/NumAdultsLbl"
android:text="@string/NumAdultsLbl" android:layout_weight="2"></TextView>
<TextView android:textColor="@color/custom_theme_text_color"
android:layout_height="wrap_content" android:id="@+id/NumChildLbl"
android:layout_weight="2" android:text="@string/NumChildLbl"></TextView>
</TableRow>
<TableRow android:id="@+id/tableRow2" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_weight="1">
<Spinner android:layout_height="wrap_content" android:id="@+id/NumNightsSpinner"
android:layout_width="wrap_content" android:layout_weight="1"></Spinner>
<Spinner android:layout_height="wrap_content" android:id="@+id/NumChildSpinner"
android:layout_width="wrap_content" android:layout_weight="1"></Spinner>
</TableRow>
</TableLayout>
<Button android:layout_width="match_parent" android:id="@+id/CheckAvailabilityBtn"
android:layout_height="wrap_content" android:text="@string/CheckAvailableBtn"
android:layout_weight="1" />
</LinearLayout>
基本上我需要知道的是如何获取 Availability.class
文件来使用第二个 xml 文件?< /em> 我所看到的只是看起来很棒的选项卡! 我不想在主代码中创建按钮等,因为我试图尽可能面向对象。我见过的所有示例都使用 tabs.xml 来布局活动,如果您希望每个选项卡都具有相同的信息,或者布局内容直接写入 java 类,那么这非常有用。
可以做我想做的事吗?如果是这样,有人可以建议我如何执行此操作或将我链接到某个地方吗?
I am trying to create a tabbed interface which has multiple activities. As part of the tabs I have created and set an xml tabhost file like so:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
This is called in my Tabs.class file which looks like this:
package com.system.kenetix;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
public class Tabs extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs);
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, Availability.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("Availability").setIndicator("Booking",
res.getDrawable(R.drawable.kenetix_tab_available))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, RoomsAvailable.class);
spec = tabHost.newTabSpec("Room").setIndicator("Rooms",
res.getDrawable(R.drawable.kinetix_tab_rooms))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, CustomerDetails.class);
spec = tabHost.newTabSpec("Customer").setIndicator("Customer",
res.getDrawable(R.drawable.kinetix_tab_customer))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Payment.class);
spec = tabHost.newTabSpec("Payment").setIndicator("Payment",
res.getDrawable(R.drawable.kinetix_tab_payment))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Extras.class);
spec = tabHost.newTabSpec("Extras").setIndicator("Extras",
res.getDrawable(R.drawable.kinetix_tab_extras))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
}
I then have individual classes for each of my tabs and an xml file to set the content (Buttons, spinners etc) like so:
package com.system.kenetix;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;
public class Availability extends Activity {
/** Called when the activity is first created. */
Intent intent = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.availability);
/*Nights Spinner*/
//Create an instance of the Number of Nights spinner
Spinner NumNightsSpinner = (Spinner) findViewById(R.id.NumAdultsSpinner);
//Create an ArrayAdapter for the Number of Nights spinner
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.NumNights_array, android.R.layout.simple_spinner_item);
//Set the adapter layout
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//Apply the adapter layout to the Number of Nights spinner
NumNightsSpinner.setAdapter(adapter);
NumNightsSpinner.setOnItemSelectedListener(new MyOnNumNightsSelectedListener());
/*Adults Spinner*/
//Create an instance of the Number of Adults spinner
Spinner NumAdultsSpinner = (Spinner) findViewById(R.id.NumAdultsSpinner);
//Create an ArrayAdapter for the Number of adults spinner
ArrayAdapter<CharSequence> adapter1 = ArrayAdapter.createFromResource(this, R.array.NumAdults_array, android.R.layout.simple_spinner_item);
//Set the adapter layout
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//Apply the adapter layout to the Number of Adults spinner
NumAdultsSpinner.setAdapter(adapter);
NumAdultsSpinner.setOnItemSelectedListener(new MyOnNumAdultsSelectedListener());
/*Children Spinner*/
//Create an instance of the Number of Children spinner
Spinner NumChildSpinner = (Spinner) findViewById(R.id.NumChildSpinner);
//Create an ArrayAdapter for the Number of Children spinner
ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(this, R.array.NumChild_array, android.R.layout.simple_spinner_item);
//Set the adapter layout
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//Apply the adapter layout to the Number of Children spinner
NumChildSpinner.setAdapter(adapter);
NumChildSpinner.setOnItemSelectedListener(new MyOnNumChildSelectedListener());
Button CheckAvailable = (Button) findViewById(R.id.CheckAvailabilityBtn);
CheckAvailable.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
intent = new Intent(v.getContext(), RoomsAvailable.class);
startActivity(intent);
}
});
}
//Listener for the selected item from the number of nights spinner
public class MyOnNumNightsSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent,View view, int pos, long id){
//If no number of nights has been selected or onCreate occurs cancel the toast
if (parent.getItemAtPosition(pos).toString().equals("0")){
Toast.makeText(parent.getContext(), "You selected " + parent.getItemAtPosition(pos).toString() + " night(s)", Toast.LENGTH_LONG).cancel();
}
//Else create a toast stating the number of nights selected
else{
Toast.makeText(parent.getContext(), "You selected " + parent.getItemAtPosition(pos).toString() + " night(s)", Toast.LENGTH_LONG).show();
}
}
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
}
//Listener for the selected item from the number of adults spinner
public class MyOnNumAdultsSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent,View view, int pos, long id){
//If no number of nights has been selected or onCreate occurs cancel the toast
if (parent.getItemAtPosition(pos).toString().equals("0")){
Toast.makeText(parent.getContext(), "You selected " + parent.getItemAtPosition(pos).toString() + " adults", Toast.LENGTH_LONG).cancel();
}
else if (parent.getItemAtPosition(pos).toString().equals("1")){
Toast.makeText(parent.getContext(), "You selected " + parent.getItemAtPosition(pos).toString() + " adult", Toast.LENGTH_LONG).cancel();
}
//Else create a toast stating the number of nights selected
else{
Toast.makeText(parent.getContext(), "You selected " + parent.getItemAtPosition(pos).toString() + " adult(s)", Toast.LENGTH_LONG).show();
}
}
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
//Do Nothing
}
}
//Listener for the selected item from the number of adults spinner
public class MyOnNumChildSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent,View view, int pos, long id){
//If no number of nights has been selected or onCreate occurs cancel the toast
if (parent.getItemAtPosition(pos).toString().equals("0")){
Toast.makeText(parent.getContext(), "You selected " + parent.getItemAtPosition(pos).toString() + " children", Toast.LENGTH_LONG).cancel();
}
else if (parent.getItemAtPosition(pos).toString().equals("1")){
Toast.makeText(parent.getContext(), "You selected " + parent.getItemAtPosition(pos).toString() + " child", Toast.LENGTH_LONG).show();
}
//Else create a toast stating the number of nights selected
else{
Toast.makeText(parent.getContext(), "You selected " + parent.getItemAtPosition(pos).toString() + " children", Toast.LENGTH_LONG).show();
}
}
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
//Do Nothing
}
}
}
and the xml that goes with this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1" android:background="@color/custom_theme_color"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:baselineAligned="false" android:orientation="vertical">
<TableLayout android:layout_width="wrap_content"
android:layout_alignParentLeft="true" android:layout_height="wrap_content"
android:id="@+id/tableLayout1" android:stretchColumns="1"
android:layout_weight="1">
<TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton android:src="@drawable/icon"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:id="@+id/QuickRoomSelect" android:layout_weight="1" />
<ImageButton android:src="@drawable/icon"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:id="@+id/QuickCustomerDetails" android:layout_weight="1" />
<ImageButton android:src="@drawable/icon"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:id="@+id/imageButton1" android:layout_weight="1" />
</TableRow>
</TableLayout>
<TextView android:layout_width="match_parent"
android:textColor="@color/custom_theme_text_color" android:id="@+id/availabilityLbl"
android:text="@string/AvailableLbl" android:layout_height="wrap_content"
android:layout_weight="1" />
<Button android:layout_height="wrap_content" android:id="@+id/DateFromBtn"
android:layout_width="match_parent" android:text="@string/DateFromBtn"
android:layout_weight="1" />
<TextView android:textColor="@color/custom_theme_text_color"
android:layout_height="wrap_content" android:id="@+id/NumNightsLdl"
android:text="@string/NumNightsLbl" android:layout_width="wrap_content"
android:layout_weight="1"></TextView>
<Spinner android:layout_height="wrap_content" android:id="@+id/NumAdultsSpinner"
android:layout_width="wrap_content" android:layout_weight="1"></Spinner>
<TableLayout android:layout_height="wrap_content"
android:id="@+id/tableLayout2" android:layout_width="match_parent"
android:layout_weight="1">
<TableRow android:id="@+id/tableRow3" android:layout_height="wrap_content"
android:layout_width="match_parent" android:layout_weight="1">
<TextView android:textColor="@color/custom_theme_text_color"
android:layout_height="wrap_content" android:id="@+id/NumAdultsLbl"
android:text="@string/NumAdultsLbl" android:layout_weight="2"></TextView>
<TextView android:textColor="@color/custom_theme_text_color"
android:layout_height="wrap_content" android:id="@+id/NumChildLbl"
android:layout_weight="2" android:text="@string/NumChildLbl"></TextView>
</TableRow>
<TableRow android:id="@+id/tableRow2" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_weight="1">
<Spinner android:layout_height="wrap_content" android:id="@+id/NumNightsSpinner"
android:layout_width="wrap_content" android:layout_weight="1"></Spinner>
<Spinner android:layout_height="wrap_content" android:id="@+id/NumChildSpinner"
android:layout_width="wrap_content" android:layout_weight="1"></Spinner>
</TableRow>
</TableLayout>
<Button android:layout_width="match_parent" android:id="@+id/CheckAvailabilityBtn"
android:layout_height="wrap_content" android:text="@string/CheckAvailableBtn"
android:layout_weight="1" />
</LinearLayout>
Basically what I need to know is how do I get the Availability.class
file to use the second xml file? All that I can see is the tabs which looks great! I don't want to have to create the buttons etc. in the main code as I'm trying to be as OO as possible. All of the examples I have seen either use the tabs.xml to layout the activity which is great if you want every tab to have the same information, or the layout stuff is written straight into the java class.
Is it possible to do what I want? If so can someone advise me in how to do this or link me to somewhere?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你想要的基本上就是我的应用程序的组织方式(我正在摆弄第二个版本,它是基于视图的)。
不过,您的 Tabs XML 文件似乎存在一些问题。
1)为什么你有两次 xmlns:android 标签? TabHost 和 LinearLayout 都有它 - 从 LinearLayout 中删除一个。
2)不确定 LinearLayout 上的 match_parent 布局参数(但这可能不是问题) - 我的第一个 TabHost (后来修改了一下)看起来像这样,这与你的非常相似(我想我们遵循相同的教程Android 文档;)),并且工作得很好:
尝试修复第一件事,它应该工作得很好,我认为没有理由不应该。
What you want is basically exactly how my application is organized (with a second version I am fiddling around with that is View-based instead).
There seems to be a bit of an issue with your Tabs XML file though.
1) Why do you have the xmlns:android tag twice? TabHost and LinearLayout both have it - remove the one from the LinearLayout.
2) Not sure about the match_parent layout params on the LinearLayout (this is likely not the issue though) - my first TabHost (later revised a bit) looked like this, which is very similar to yours (I imagine we followed the same tutorial off the Android docs ;)), and worked just fine:
Try to fix the first thing and it should work just fine, I see no reason it shouldn't.