English 中文(简体)
在每个表态中要求同样的活动
原标题:Call same activity in every tab setContent()
  • 时间:2011-06-16 06:01:53
  •  标签:
  • android

我有一份表格活动,其中每一个表格都称同一活动,请上。 因此,我希望我的<代码>MyTabInterface能够拿到哪条信息。 我试图用以下法典来这样做,但似乎有工作要做。

intent = new Intent().setClass(this,MyTabInterface.class);
intent.putExtra("interface",tabs.elementAt(0).getAction());
intent.putExtra("data",tabs.elementAt(0).getData());
spec = tabHost.newTabSpec(tabs.elementAt(0).getName()).setIndicator(tabs.elementAt(0).getLabel().toString(),res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);
tabHost.addTab(spec);


intent = new Intent().setClass(this,MyTabInterface.class);
intent.putExtra("interface","table");
intent.putExtra("data","table_data");
spec= tabHost.newTabSpec(tabs.elementAt(1).getName()).setIndicator(tabs.elementAt(1).getLabel().toString(),res.getDrawable(R.drawable.ic_tab_artists))
.setContent(intent);
tabHost.addTab(spec);

我的看法将根据外观细节改变。 这里指两种表格中的同一活动类别。 阴表正确显示。 但第二种情况与第一类情况相同。

How can I solve this problem ?

最佳回答

这里是一部关于贱民的法典,希望这样做有助于:

public class InfralineTabWidget extends android.app.TabActivity{

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    @SuppressWarnings("unused")
    Resources res = getResources();
    TabHost tabHost = (TabHost)getTabHost();

    TabHost.TabSpec spec;
    @SuppressWarnings("unused")
    Intent intent;
 tabHost.getTabWidget().setBackgroundDrawable(getResources().getDrawable(R.drawable.bluenavbar));
    TextView  txtTab = new TextView(this);
        txtTab.setText(getString(R.string.top_news));
        txtTab.setPadding(8, 9, 8, 9);
        txtTab.setTextColor(Color.WHITE);
        txtTab.setTextSize(14);
    txtTab.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
        txtTab.setBackgroundResource(R.drawable.tab_news);
    intent = new Intent().setClass(this, TopNewsGroup.class);
    spec = tabHost.newTabSpec("topNews").setIndicator(txtTab).setContent(new Intent(this,TopNewsGroup.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP ));
    tabHost.addTab(spec);

    TextView  txtTab1 = new TextView(this);
    txtTab1.setText(getString(R.string.power));
    txtTab1.setPadding(8, 9, 8, 9);
    txtTab1.setTextColor(Color.WHITE);
    txtTab1.setTextSize(14);
    txtTab1.setTypeface(localTypeface1);
    txtTab1.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
    txtTab1.setBackgroundResource(R.drawable.tab_power);
    intent = new Intent().setClass(this, PowerGroup.class);
    spec = tabHost.newTabSpec("power").setIndicator(txtTab1).setContent(new Intent(this,PowerGroup.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP ));
    tabHost.addTab(spec);


    tabHost.setCurrentTab(0);
        tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 100;
        tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 100;

        tabHost.getTabWidget().getChildAt(0).getLayoutParams().width = 160;
        tabHost.getTabWidget().getChildAt(1).getLayoutParams().width = 160;    

iii

iii

问题回答
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.maiin);




        final TabHost tabHost = (TabHost) getTabHost();
        try {               

            tabHost.addTab(createTab(FIRST_ACTIVITY_NAME.class, "eter",
                    "eter", R.drawable.tab_icon_events));
            tabHost.addTab(createTab(SECONDACTIVITY_NAME.class, ".abc", ".abc",
                    R.drawable.tab_icon_pitchforkfm));
            tabHost.addTab(createTab(THIRD_ACTIVTY_NAME.class, "xyz", "xyz",
                    R.drawable.tab_icon_home));
            tabHost.addTab(createTab(ExtraInfromation.class, "wewr", "wewr",
                    R.drawable.tab_icon_tv));       


            tabHost.setCurrentTab(1);
        } catch (Exception e) {
            // TODO: handle exception
        }    
        tabHost.getTabWidget().getChildAt(0).getLayoutParams().width = 85;

        tabHost.getTabWidget().getChildAt(1).getLayoutParams().width = 85;
        tabHost.getTabWidget().getChildAt(2).getLayoutParams().width = 85;
        tabHost.getTabWidget().getChildAt(3).getLayoutParams().width = 85;
tabHost.setOnTabChangedListener(new OnTabChangeListener() {

    @Override
    public void onTabChanged(String tabID) {
        // TODO Auto-generated method stub
        if( tabID.equals(".xyz") ){


        //DO SOMETHING 
        }

    }
});
    }



    private TabSpec createTab(final Class<?> intentClass, final String tag,
            final String title, final int drawable) {
        final Intent intent = new Intent().setClass(this, intentClass);

        final View tab = LayoutInflater.from(getTabHost().getContext())
                .inflate(R.layout.tab, null);
        ((TextView) tab.findViewById(R.id.tab_text)).setText(title);
        ((ImageView) tab.findViewById(R.id.tab_icon))
                .setImageResource(drawable);

        return getTabHost().newTabSpec(tag).setIndicator(tab)
                .setContent(intent);

    }




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签