0

this is my login view http://i.imgur.com/IfLIHFQ.jpg , a successful login will redirect to this page http://i.imgur.com/4yv3KDv.jpg but, instead of launch a new intent, I want the activity is proceed within the tab. This is how I describe it http://i.imgur.com/sH8HQC7.jpg (Note: The last pic is just an edited photoshop in order to give you a sample of what I want it to be). Sorry for asking newbie question, I appreciate your help thanks before.

This is my code : Tab1.java

public class Tab1 extends Activity {
    String var_usr,var_pass;
    EditText usr, psw;
    JSONArray str_login = null;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.panel_login);

        usr = (EditText) findViewById(R.id.txt_username);
        psw = (EditText) findViewById(R.id.txt_pass);


        Button submit = (Button) findViewById(R.id.btn_login);
        submit.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

                var_usr = usr.getText().toString();
                var_pass = psw.getText().toString();
                String stts = "";
                String kode = "";
                String link_url = "http://10.0.2.2/gollege/login.php?usr="+var_usr+"&psw="+var_pass;
                com.bucheuw.gollege.portal.JSONParser jParser = new com.bucheuw.gollege.portal.JSONParser();
                JSONObject json = jParser.AmbilJson(link_url);

                try {
                    str_login = json.getJSONArray("statuslogin");

                    for(int i = 0; i < str_login.length(); i++){
                        JSONObject ar = str_login.getJSONObject(i);
                        TextView st = (TextView) findViewById(R.id.txt_alert);
                        String alrt = ar.getString("hasil");
                        stts = ar.getString("st");
                        kode = ar.getString("id");
                        st.setText(alrt);
                        usr.setText("");
                        psw.setText("");

                        if(stts.trim().equals("ok"))
                        {
                            Intent ni = null;                           
                            ni = new Intent(Tab1.this, com.bucheuw.gollege.portal.DashboardActivity.class);
                            Bundle b = new Bundle();
                            b.putString("par_kode", kode);
                            ni.putExtras(b);
                            startActivity(ni);
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }

DashboardAcitvity.java

public class DashboardActivity extends Activity {

    public String nim;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.panel_dashboard);

        Bundle b = getIntent().getExtras();
        nim = b.getString("par_kode");

        Button btn_datapribadi = (Button) findViewById(R.id.btn_datapribadi);
        Button btn_ksm = (Button) findViewById(R.id.btn_ksm);
        Button btn_jdwlkuliah = (Button) findViewById(R.id.btn_jdwlkuliah);
        Button btn_absensi = (Button) findViewById(R.id.btn_absensi);
        Button btn_nilai = (Button) findViewById(R.id.btn_nilai);
        Button btn_tak = (Button) findViewById(R.id.btn_tak);
        Button btn_ips = (Button) findViewById(R.id.btn_ips);
        Button btn_jdwlujian = (Button) findViewById(R.id.btn_jdwlujian);
        Button btn_pengumuman = (Button) findViewById(R.id.btn_pengumuman);
        Button btn_klndr = (Button) findViewById(R.id.btn_klndr);
        Button btn_logout = (Button) findViewById(R.id.btn_logout);

        btn_datapribadi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {                        
                Intent i = new Intent(getApplicationContext(), DataPribadiActivity.class);
                startActivity(i);
            }
        });

        btn_ksm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {                        
                Intent i = new Intent(getApplicationContext(), KSMActivity.class);
                startActivity(i);
            }
        });

        btn_jdwlkuliah.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {                        
                Intent i = new Intent(getApplicationContext(), JadwalKuliahActivity.class);
                startActivity(i);
            }
        });

        btn_absensi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {                        
                Intent i = new Intent(getApplicationContext(), AbsensiActivity.class);
                startActivity(i);
            }
        });

        btn_nilai.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {                        
                Intent i = new Intent(getApplicationContext(), NilaiActivity.class);
                startActivity(i);
            }
        });

        btn_tak.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {                        
                Intent i = new Intent(getApplicationContext(), TAKActivity.class);
                startActivity(i);
            }
        });

       btn_ips.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {                        
                Intent i = new Intent(getApplicationContext(), IPSActivity.class);
                startActivity(i);
            }
        });

        btn_jdwlujian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {                        
                Intent i = new Intent(getApplicationContext(), JadwalUjianActivity.class);
                startActivity(i);
            }
        });

        btn_pengumuman.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {                        
                Intent i = new Intent(getApplicationContext(), InfoKampusActivity.class);
                startActivity(i);
            }
        });

        btn_klndr.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {                        
                Intent i = new Intent(getApplicationContext(), KalenderAkademikActivity.class);
                startActivity(i);
            }
        });

        btn_logout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {    
                    Intent exit = new Intent(Intent.ACTION_MAIN);
                    exit.addCategory(Intent.CATEGORY_HOME); exit.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    DashboardActivity.this.finish();

            }
        });
    }
4

1 回答 1

0

在创建 tabhost 的父活动类中,我实现了如下方法:

public void switchTab(int tab){
            tabHost.setCurrentTab(tab);
}

在我希望能够在内部切换到另一个选项卡的选项卡内部,我创建了以下方法:

public void switchTabInActivity(int indexTabToSwitchTo){
            MintTrack ParentActivity;
            ParentActivity = (MintTrack) this.getParent();
            ParentActivity.switchTab(indexTabToSwitchTo);
}

如果您想要此代码的一个很好的示例,您可以在此处此处查看我的 MintTrack 项目。

附带说明一下,在决定是使用基于视图还是基于活动的 TabHost 时,请务必小心。

基于活动的选项卡很棒,因为它们可以分离到自己的 XML 文件中。活动也可以组织到自己的 Java 文件中,而不是混乱成一个。话虽这么说,一些你认为很容易的事情会因为基于活动的选项卡而变得复杂。很难在选项卡之间传递信息而不产生开销。基于活动的选项卡也使用更多的内存/CPU 时间,因为它们有围绕它们的活动的开销。在深入使用基于 Activity 的 TabHost 之前,请考虑这一点以及更多的权衡。我现在知道,如果我再次使用它们,我会亲自使用基于视图的 TabHost。

于 2013-01-24T09:17:44.897 回答