如何在 Tabhost 中集成单选按钮?
我已经在 Android SDK (2.3.3) 中制作了一个完整工作的三个 TAB-GUI,但我想将几个单选按钮和一个单选组集成到一个 TAB 中。我是 android 新手,所以我希望有人可以帮助我?
主代码和相应的类代码如下:
MAIN
package com.example.androidtablayout;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class AndroidTabLayoutActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
// Tab for Dag
TabSpec dagspec = tabHost.newTabSpec("Dag");
dagspec.setIndicator("DagRooster", getResources().getDrawable(R.drawable.icon_dag_tab));
Intent dagIntent = new Intent(this, DagActivity.class);
dagspec.setContent(dagIntent);
// Tab for Norm
TabSpec normspec = tabHost.newTabSpec("Norm");
// setting Title and Icon for the Tab
normspec.setIndicator("Normaal", getResources().getDrawable(R.drawable.icon_norm_tab));
Intent normIntent = new Intent(this, NormActivity.class);
normspec.setContent(normIntent);
// Tab for Instel
TabSpec instelspec = tabHost.newTabSpec("Instel");
instelspec.setIndicator("Info", getResources().getDrawable(R.drawable.icon_setting_tab));
Intent instelIntent = new Intent(this, InstelActivity.class);
instelspec.setContent(instelIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(dagspec); // Adding photos tab
tabHost.addTab(normspec); // Adding songs tab
tabHost.addTab(instelspec); // Adding videos tab
}
}
NORM-CLASS 代码
package com.example.androidtablayout;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
public class NormActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.instel_layout);
}
}
I've made a full working three TAB-GUI in Android SDK (2.3.3) but I want to integrate several radiobuttons and one radiogroup into a TAB. I'm a android-newbe so I hope somebody can help me?
Hereby the main-code and the according Class-code:
MAIN
package com.example.androidtablayout;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class AndroidTabLayoutActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
// Tab for Dag
TabSpec dagspec = tabHost.newTabSpec("Dag");
dagspec.setIndicator("DagRooster", getResources().getDrawable(R.drawable.icon_dag_tab));
Intent dagIntent = new Intent(this, DagActivity.class);
dagspec.setContent(dagIntent);
// Tab for Norm
TabSpec normspec = tabHost.newTabSpec("Norm");
// setting Title and Icon for the Tab
normspec.setIndicator("Normaal", getResources().getDrawable(R.drawable.icon_norm_tab));
Intent normIntent = new Intent(this, NormActivity.class);
normspec.setContent(normIntent);
// Tab for Instel
TabSpec instelspec = tabHost.newTabSpec("Instel");
instelspec.setIndicator("Info", getResources().getDrawable(R.drawable.icon_setting_tab));
Intent instelIntent = new Intent(this, InstelActivity.class);
instelspec.setContent(instelIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(dagspec); // Adding photos tab
tabHost.addTab(normspec); // Adding songs tab
tabHost.addTab(instelspec); // Adding videos tab
}
}
NORM-CLASS code
package com.example.androidtablayout;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
public class NormActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.instel_layout);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您想要 radioButtons 的活动中,.. 不是 TabActivty.. 尝试如下所示的操作。注意:请注意单选按钮的内容。我在发布之前撕下了一些位置管理代码。但单选按钮逻辑会让你得到你想要的。
在你的 TabHost 中,你将需要这样的东西来管理 Intent/Bundle
和所需的 XML。首先,你需要将其包装在 XML 中,以便你希望单选按钮显示的屏幕
In the activity you want the radioButtons, .. Not TabActivty.. try something like this below. NB: pay atention to the radiobutton stuff.. I ripped some code for location management out before posting. But the radioButton logic will get you what you want.
In your TabHost you will need something like this to manage the Intent/Bundle
And the needed XML.. Just a start, you'll need to wrap this inside your XML for the screen you want radioButtons to show up