让tabhost的每个tab按钮显示自己的view

package com.ftonline;


import android.app.TabActivity;
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.ftonline.ui.FenLeiActivity;
import com.ftonline.ui.JingXuanActivity;
import com.ftonline.ui.SheZhiActivity;
import com.ftonline.ui.WoDeActivity;


public class MainActivity extends TabActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);


TabHost tabHost = getTabHost();


Intent intent1 = new Intent();
intent1.setClass(this, JingXuanActivity.class);

// TabHost.TabSpec tab1 = tabHost.newTabSpec("tab1");
// tab1.setIndicator("精选");
// tab1.setContent(intent1);



tabHost.addTab(tabHost
.newTabSpec("tab1")
.setIndicator(
getIndicatorView(R.drawable.meinv,                           //注意这里,这个方法在下面声明
"ddddddd"))
.setContent(
intent1));





Intent intent2 = new Intent();
intent2.setClass(this, FenLeiActivity.class);
TabHost.TabSpec tab2 = tabHost.newTabSpec("tab2");
tab2.setIndicator("分类");
tab2.setContent(intent2);


Intent intent3=new Intent();
intent3.setClass(this,WoDeActivity.class);
TabHost.TabSpec tab3=tabHost.newTabSpec("tab3");
tab3.setIndicator("我的");
tab3.setContent(intent3);

Intent intent4=new Intent();
intent4.setClass(this,SheZhiActivity.class);
TabHost.TabSpec tab4=tabHost.newTabSpec("tab4");
tab4.setIndicator("设置");
tab4.setContent(intent4);

// Intent intent5=new Intent();
// intent5.setClass(this,FeedBack.class);
// TabHost.TabSpec tab5=tabHost.newTabSpec("tab5");
// tab5.setIndicator("问题反馈");
// tab5.setContent(intent5);
//

//tabHost.addTab(tab1);
tabHost.addTab(tab2);
   tabHost.addTab(tab3);
tabHost.addTab(tab4);
// tabHost.addTab(tab5);
//tabHost.setup();
}


LayoutInflater mInflater;
   

protected View getIndicatorView(int resId, String title) {
mInflater = LayoutInflater.from(this); 

View _View = mInflater.inflate(R.layout.jingxuan_item, null);
ImageView mImageView = (ImageView) _View.findViewById(R.id.jingxuan_imageView1);
TextView mTextView = (TextView) _View.findViewById(R.id.jingxuan_textView1);
   mImageView.setImageResource(R.drawable.meinv);
mTextView.setText(title);
mTextView.setTextSize(30);
return _View;
}



}

你可能感兴趣的:(String,null,Class)