里面TAB键不点击/响应 [英] Buttons inside TAB dont clickable/responding
本文介绍了里面TAB键不点击/响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的应用程序使用TabHost做TABS。
一个选项卡中有两个按钮,它(按钮,anotherButton)
I have done TABS in my app using TabHost. one of the tabs has two buttons in it("button","anotherButton")
在我跑我的应用程序,我可以看到两个标签,但是当我美元,其中p $ PSS什么happend(他们甚至不点击当我preSS他们。),更在他们不给任何听众回应我加入他们。
After I run my app I can see both tabs, but when I press on them nothing happend(they dont even "clickable" when I press them.) And more over They dont respond to any listeners which I add to them.
一些code:
main.xml中:
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_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">
<AnalogClock android:id="@+id/tab1" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_centerHorizontal="true" />
<LinearLayout android:id="@+id/linearbuttonsview"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
----pay attention here I decalred tab with two buttons !!! -----------------
<Button android:id="@+id/button" android:layout_width="wrap_content"
android:onClick="onSemiButtonClick" android:layout_height="wrap_content" android:text="A semi-random button" />
<Button android:id="@+id/anotherButton" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="A semi-semi-random button"
android:scrollY="400px" />
</LinearLayout>
<ListView android:id="@+id/tablist" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
</LinearLayout>
</TabHost>
这就是我的code:
thats my code:
public class TabDemo extends Activity
{
private ListView ls1;
private Button semiButton;
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
ls1 = new ListView(TabDemo.this);
TabHost tabs = (TabHost) findViewById(R.id.tabhost);
semiButton = (Button) findViewById(R.id.button);
semiButton.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
int z = 0;
z++;
}
});
tabs.setup();
// tab1
TabSpec spec = tabs.newTabSpec("tag1");
spec.setContent(R.id.tab1);
spec.setIndicator("Clock");
tabs.addTab(spec);
// tab2
spec = tabs.newTabSpec("tag2");
spec.setContent(R.id.linearbuttonsview);
spec.setIndicator("Button");
tabs.addTab(spec);
// tab3
spec = tabs.newTabSpec("tag3");
spec.setContent(new TabHost.TabContentFactory()
{
// we create a list view and give it as a reference to the the
// content
public View createTabContent(String tag)
{
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
TabDemo.this, android.R.layout.simple_list_item_1,
new String[]
{ "item1", "item2", "item3" });
ls1.setAdapter(adapter);
return ls1;
}
});
spec.setIndicator("List");
tabs.addTab(spec);
}
}
在此先感谢,
射线。
Thanks in advance, ray.
推荐答案
在您的code一些变化(创建具有不同活动的每个选项卡)
some change in your code (create each tab with different activity)
public class TabBarExample extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab);
TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);
TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
TabSpec secondTabSpec = tabHost.newTabSpec("tid1");
firstTabSpec.setIndicator("First Tab").setContent(new Intent(this,FirstTab.class));
secondTabSpec.setIndicator("Second Tab").setContent(new Intent(this,SecondTab.class));
tabHost.addTab(firstTabSpec);
tabHost.addTab(secondTabSpec);
}
}
FirstTab.java
FirstTab.java
public class FirstTab extends Activity {
Button bt;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs1);
bt = (Button) findViewById(R.id.button1);
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(FirstTab.this, "it's works", 2000).show();
}
});
}
}
tab.xml
tab.xml
<TabHost android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost">
<LinearLayout android:id="@+id/LinearLayout01"
android:orientation="vertical" android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TabWidget android:id="@android:id/tabs"
android:layout_height="wrap_content" android:layout_width="fill_parent"></TabWidget>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_height="fill_parent" android:layout_width="fill_parent"></FrameLayout>
</LinearLayout>
</TabHost>
tab1.xml
tab1.xml
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button android:text="Button" android:id="@+id/button1"
android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
这篇关于里面TAB键不点击/响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文