更改android选项卡中的布局/内容

时间:2011-12-27 02:02:52

标签: android

我目前有这个使用tabactivity创建4个标签的代码:

public class toknapp extends TabActivity {

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

        Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost();  // The activity TabHost
        TabHost.TabSpec spec;  // Resusable TabSpec for each tab
        Intent intent;  // Reusable Intent for each tab

        intent = new Intent().setClass(this, login2.class);
        spec = tabHost.newTabSpec("login").setIndicator("Login")
                      .setContent(intent);
        tabHost.addTab(spec);


        intent = new Intent().setClass(this, QuestsActivity.class);
        spec = tabHost.newTabSpec("artists").setIndicator("Quests")
                      .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, BadgeActivity.class);
        spec = tabHost.newTabSpec("albums").setIndicator("Badges")
                      .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, InfoActivity.class);
        spec = tabHost.newTabSpec("songs").setIndicator("Tokn")
                      .setContent(intent);
        tabHost.addTab(spec);

        tabHost.setCurrentTab(0);
    }
}

我想在此之后更改“任务”标签中的标签内容/布局(到myquests.xml):

protected void onPostExecute(String response) {
            String res=response.toString();
           // res = res.trim();
            res= res.replaceAll("\\s+","");   
            if(!res.equals("0")){
                un.setVisibility(View.GONE);
                ok.setVisibility(View.GONE);
                error.setVisibility(View.GONE);
                key.setVisibility(View.GONE);
                merchant.setVisibility(View.VISIBLE);
                merchant_id.setVisibility(View.VISIBLE); 
                JSONObject jObject;
                try {
                    jObject = new JSONObject(res);
                    String data = jObject.getString("merchant_name");
                    String Id = jObject.getString("merchant_id");
                    merchant_id.setText(Id);
                    merchant.setText(data);
                } catch (Exception  e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

1 个答案:

答案 0 :(得分:0)

使用像这样的活动组

view = getLocalActivityManager()。startActivity(" ReferenceName",new Intent(view.getContext(),myquests.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))。getDecorView(); 的setContentView(视图);