Android 自定义视图位于选项卡中时自定义视图中的按钮
问题 是否可以从其他三个不同的活动或Java文件运行一个选项卡,从而允许我将第二个活动连接到运行第一个活动的服务器 我的应用程序上的一些信息Android 自定义视图位于选项卡中时自定义视图中的按钮,android,xml,view,tabs,Android,Xml,View,Tabs,问题 是否可以从其他三个不同的活动或Java文件运行一个选项卡,从而允许我将第二个活动连接到运行第一个活动的服务器 我的应用程序上的一些信息 th.setup(); TabSpec specs = th.newTabSpec("tag0"); specs.setContent(R.id.connecttionTab); specs.setIndicator("Connection Tab"); th.addTab(specs); specs = t
th.setup();
TabSpec specs = th.newTabSpec("tag0");
specs.setContent(R.id.connecttionTab);
specs.setIndicator("Connection Tab");
th.addTab(specs);
specs = th.newTabSpec("tag1");
specs.setContent(R.id.tab1);
specs.setIndicator("Zone Manager");
th.addTab(specs);
specs = th.newTabSpec("tag2");
specs.setContent(R.id.tab2);
specs.setIndicator("",res.getDrawable(R.drawable.ic_tab_vaccontrol));
th.addTab(specs);
//Intent intent = new Intent().setClass(this, Tab3Activity.class); tryed using this but
//with this tab goes ontop of all the other ones and still doesnt work.
TabSpec spec = th.newTabSpec("Tab3").setIndicator("Graphical Layout").setContent(R.id.tab3);
th.addTab(spec);
我有一个多标签的应用程序,有一些不同的布局。其中之一是交互式图形布局。在这个选项卡上,大部分内容需要是我已经设置好的自定义视图,但我需要在底部有一行小部件,如按钮、滑块等。如果我将其设置为主要活动来运行图形布局(android:name=“.Tab3Activity”
)在清单中,当我单击按钮时,应用程序将运行并打印文本。如果我从选项卡中运行它,因为我需要它来运行,则当我单击按钮时,应用程序将崩溃。这是我目前拥有的代码
选项卡设置
th.setup();
TabSpec specs = th.newTabSpec("tag0");
specs.setContent(R.id.connecttionTab);
specs.setIndicator("Connection Tab");
th.addTab(specs);
specs = th.newTabSpec("tag1");
specs.setContent(R.id.tab1);
specs.setIndicator("Zone Manager");
th.addTab(specs);
specs = th.newTabSpec("tag2");
specs.setContent(R.id.tab2);
specs.setIndicator("",res.getDrawable(R.drawable.ic_tab_vaccontrol));
th.addTab(specs);
//Intent intent = new Intent().setClass(this, Tab3Activity.class); tryed using this but
//with this tab goes ontop of all the other ones and still doesnt work.
TabSpec spec = th.newTabSpec("Tab3").setIndicator("Graphical Layout").setContent(R.id.tab3);
th.addTab(spec);
选项卡3活动
public class Tab3Activity extends Activity
{
private Tab3 mTab3;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.tab3);
mTab3 = (Tab3) findViewById(R.id.tab3_display);
}
public void onAddZone(View view)
{
mTab3.addZone();
}
}
Tab3(视图类)
XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="@+id/myLayout"
android:orientation="vertical"
android:layout_height="match_parent" >
<com.zone.manager.Tab3
android:id="@+id/tab3_display"
android:layout_width="fill_parent"
android:layout_height="620dp" />
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="match_parent" >
<Button
android:id="@+id/addZone"
android:layout_width="wrap_content"
android:onClick="onAddZone"
android:layout_height="wrap_content"
android:text="Add Zone" />
<Button
android:id="@+id/helpZone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Help" />
<SeekBar
android:id="@+id/seekBar1"
android:paddingTop="9dp"
android:layout_width="179dp"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
谢谢你给我的任何帮助 虽然我们希望您发布崩溃日志,但我建议您不要使用旧的选项卡方法(当然,除非您的客户要求使用这些选项卡)。自从tab小部件事件以来,Android的ui模式发生了严重的变化 当前实现选项卡的方法是使用和,从Honeycomb开始就有了,但在早期的android版本中,它作为支持库提供,您可以使用android sdk管理器下载。基于片段的方法将为您省去很多麻烦
至于你的主要问题,现在还不太清楚通过从不同的活动中启动一些东西,你想要完成什么,但是如果你需要从一个活动中启动一个长期运行的任务并将结果返回到另一个活动中,你可能需要仔细阅读(特别是,最有可能是你正在寻找的)StackOverflow用于编程问题。这不是一个问题。另外,您提到了一个崩溃,但是您没有提供与该崩溃相关的堆栈跟踪。对不起,这怎么不是一个问题呢?我想问的是,在自定义视图类中如何设置按钮。在英语和大多数其他欧洲语言中,一个问题用问号(“?”)表示,如您在上述评论的第一句中的问号。你的帖子没有这些,或者没有任何可以合理解释为问题的句子,只是没有标点符号。这个“问题”我已经读了好几遍,即使有了你的上述评论,我仍然不知道你在说什么。我知道你的意思。我已经更新了我的问题,所以现在它显示了我的确切问题。抱歉。米迦勒,如果你想让社区来诊断你的崩溃,你真的应该考虑发布崩溃日志。这不是我需要做的,但是我已经决定了如何去做它。不过还是谢谢你。