我有基于标签的应用程序。在一个选项卡中,我有一个扩展ListActivity的类。在保持标签栏的同时触发onClick时,我需要另一个活动。我希望在保留标签栏的同时将其转移到带有onClick的另一个标签页。
此代码有效但隐藏了标签栏:
Intent intent = new Intent(getApplicationContext(),SectionContentList.class);
// put values to intent which will get in the LoginSuccess Activity
Log.d("",appState.MainCategories.get(position).get("feedUrl"));
intent.putExtra("FeedURL", appState.MainCategories.get(position).get("feedUrl"));
// Start LoginSuccess Activity
startActivity(intent);
如何在保留底部标签栏的同时转移到这个新意图?
答案 0 :(得分:2)
我已经举例说明了标签活动管理 //已经声明了Activity的使用数量 包com.technosoft.Concina_Peru;
import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;
import com.technosoft.FirstTab.FirstTab;
import com.technosoft.FourthTab.FourthTab;
import com.technosoft.SecondTab.SecondTab;
import com.technosoft.ThirdTab.ThirdTab;
public class ConcinaPeruTabbar extends TabActivity {
public static Context tabContext;
public static TabHost tabHost;
Context con;
public static String var = "";
public static Concina_Database db;
private void setupTabHost() {
tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setup();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.starttab);
tabContext = this;
con = this.getApplicationContext();
db = new Concina_Database(con);
setupTabHost();
setupTab(new TextView(this), "Inicio");
setupTab(new TextView(this), "Recetas");
setupTab(new TextView(this), "Favoritos");
setupTab(new TextView(this), "Mas");
}
private void setupTab(final View view, final String tag) {
View tabview = createTabView(tabHost.getContext(), tag);
if(tag.equals("Inicio")){
tabHost.addTab((tabHost.newTabSpec("Inicio")).setIndicator(
tabview).setContent(new Intent(this, FirstTab.class)));
}
if(tag.equals("Recetas")){
tabHost.addTab((tabHost.newTabSpec("Recetas")).setIndicator(
tabview).setContent(new Intent(this, SecondTab.class)));
}
if(tag.equals("Favoritos")){
tabHost.addTab((tabHost.newTabSpec("Favoritos")).setIndicator(
tabview).setContent(new Intent(this, ThirdTab.class)));
}
if(tag.equals("Mas")){
tabHost.addTab((tabHost.newTabSpec("Mas")).setIndicator(
tabview).setContent(new Intent(this, FourthTab.class)));
}
}
private static View createTabView(final Context context, final String text) {
View view = LayoutInflater.from(context)
.inflate(R.layout.tabs_bg, null);
TextView tv = (TextView) view.findViewById(R.id.tabsText);
ImageView iv = (ImageView) view.findViewById(R.id.imageView1);
if (text.equals("Inicio")) {
iv.setBackgroundResource(R.drawable.tab_bg_image);
}
if (text.equals("Recetas")) {
iv.setBackgroundResource(R.drawable.tab_bg_image1);
}
if (text.equals("Favoritos")) {
iv.setBackgroundResource(R.drawable.tab_bg_image2);
}
if (text.equals("Mas")) {
iv.setBackgroundResource(R.drawable.tab_bg_image3);
}
tv.setText(text);
return view;
}
}
//第一个标签活动在此定义
public class FirstTab extends ActivityGroup{
public static FirstTab group_FirstTab;
private ArrayList<View> history = new ArrayList<View>();
ProgressDialog PD;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
group_FirstTab = this;
View view = getLocalActivityManager().startActivity("CitiesAct", new
Intent(FirstTab.this,Inicio.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
replaceView(view);
}
public void replaceView(View view) {
history.add(view);
setContentView(view);
}
public void RemoveView(){
history.clear();
}
public void back(){
if(history.size() > 1) {
history.remove(history.size()-1);
setContentView(history.get(history.size()-1));
}else{
finish();
}
}
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(keyCode == KeyEvent.KEYCODE_BACK){
group_FirstTab.back();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
类似有另一个标签活动.. 现在你想在代码跟随
之后将一个标签转向另一个标签活动到另一个标签活动对于想要将0标签活动转到1标签活动,然后使用
tab activity Class tab_0{
ConcinaPeruTabbar.tabHost.setCurrentTab(1);
}
如果你想将一个标签激活到simaar tab activty,那么使用它 查看视图=
FirstTab.group_FirstTab.getLocalActivityManager().startActivity("CitiesAct", new Intent(Inicio.this,Platos.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP).putExtra("platos", "Entradas")).getDecorView();
FirstTab.group_FirstTab.replaceView(view);
答案 1 :(得分:1)
如果您已经实现了一个标签栏,那么您有一个活动 - 我们称之为MyTabActivity - 它扩展了TabActivity。
在此活动的OnCreate(Bundle)
方法中,您首先在XML中检索TabHost视图来设置标签栏:
TabHost tabHost = (TabHost) findViewById(R.id.tabhost);
要动态处理选项卡选择,可以将TabHost的引用保留为静态变量:
public static final TabHost tabHost;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabActivityLayout);
tabHost = (TabHost) findViewById(R.id.tabhost);
// .....
}
然后,您可以从其中一个选项卡活动中访问TabHost,并将当前选项卡设置如下:
MyTabActivity.tabHost.setCurrentTabByTag("the tag you affected to this activity");
OR
MyTabActivity.tabHost.setCurrentTabByTag("the id you may have affected to it");
编辑: 在影响TabHost的选项卡时会影响标记,如下所示:
TabHost.TabSpec tabSpec = tabHost.newTabSpec("The Tag").setIndicator(tabView).setContent(intent);
tabHost.addTab(tabSpec);
答案 2 :(得分:0)
您应该使用片段在多个活动之间共享部分UI。