/ /なぜ私の通常のTabhostの仕事がうまくいかないのかw。 ActionBarSherlock? -android、android-fragments、android-activity、actionbarsherlock、android-tabhost

私の通常のTabhostがうまくいかないのはなぜですか。 ActionBarSherlock? -android、android-fragments、android-activity、actionbarsherlock、android-tabhost

シンプルにしようとして髪を引っ張りますtabhostはABSで動作しますが、Androidはそれらを「改善」しようとすると、事態をより複雑にするだけのようです。私は、タブにfragemntsを使用するようにプロジェクトを変換することを検討していましたが、各タブで使用している複雑なレイアウトで非常にうまく機能することがわかりました。 Idは、今では普通のolで動作するtabhost wで解決します。作業腹筋バー。

package com.abs.tabs.fragments;

import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.Toast;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockActivity;

import com.actionbarsherlock.view.MenuItem;
import com.buhz.feeds.Buhdz;
import com.buhz.login.R;
import com.buhzhyve.localz.Localz;
import com.buhzhyve.trails.Trails;
import com.buhzhyve.trendz.Trendz;

public class FragmentTabs extends SherlockActivity {
ActionBar actionBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(SampleList.THEME); //Used for theme switching in samples
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs);


actionBar=getSupportActionBar();

Resources res = getResources(); // Resource object to get Drawables

TabHost tabHost =(TabHost) findViewById(android.R.id.tabhost);  // The activity TabHost

TabHost.TabSpec spec;  // Resusable TabSpec for each tab

Intent intent;  // Reusable Intent for each tab

// Do the same for the other tabs

intent = new Intent().setClass(this, Buhdz.class);

spec = tabHost.newTabSpec("Buhdz").setIndicator("Feeds",

res.getDrawable(R.drawable.buhdz_tab_icon))

.setContent(intent);

tabHost.addTab(spec);

// Do the same for the other tabs

intent = new Intent().setClass(this, Localz.class);

spec = tabHost.newTabSpec("Localz").setIndicator("Locals",

res.getDrawable(R.drawable.locals_tab_icon))

.setContent(intent);

tabHost.addTab(spec);



intent = new Intent().setClass(this, Trendz.class);

spec = tabHost.newTabSpec("Trendz").setIndicator("Trends",

res.getDrawable(R.drawable.trends_tab_icon))

.setContent(intent);

tabHost.addTab(spec);



intent = new Intent().setClass(this, Localz.class);

spec = tabHost.newTabSpec("convos").setIndicator("Convos",

res.getDrawable(R.drawable.convos_tab_icon))

.setContent(intent);

tabHost.addTab(spec);

// Create an Intent to launch an Activity for the tab (to be reused)

intent = new Intent().setClass(this, Trails.class);

// Initialize a TabSpec for each tab and add it to the TabHost

spec = tabHost.newTabSpec("Trails").setIndicator("Trails",

res.getDrawable(R.drawable.trails_tab_icon))

.setContent(intent);

tabHost.addTab(spec);
tabHost.setCurrentTab(4);
}

@Override
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
com.actionbarsherlock.view.MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.activity_main, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.item1:
return true;
case R.id.subItem1:
Toast.makeText(this, "Sub Menu item 1 tapped", Toast.LENGTH_SHORT).show();
return true;
case R.id.subItem2:
Toast.makeText(this, "Sub Menu item 2 tapped", Toast.LENGTH_SHORT).show();
return true;
default:
break;
}
return super.onOptionsItemSelected(item);
}
}

回答:

回答№1は0
  1. このライブラリを使用します。 https://github.com/JakeWharton/Android-ViewPagerIndicator、このライブラリ内に、必要なタブを備えたいくつかのサンプルがあり、sherlockactionbarで動作します。
  2. この質問をご覧ください: アクションバーシャーロック+タブ+マルチフラグメント?.
  3. 問題が発生した場合は私に聞いてください。