how to create menu and tab together in android

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

how to create menu and tab together in android

Postby winzone » Thu Dec 30, 2010 4:35 am

Hi All,
I am beginner of java and android.
Create Menu and Tabs sample on separate project is OK.
But when i used together in one project become error.

I have main.xml, gate.xml, login.xml, gtsmobile.java, gate.java
main.xml has welcome text display.
gate.xml has android Tab.
login.xml has login form.
==> i would like to call gate.xml or gate.java to view android TAB and its function, When i click gate from menu.
Tab example i used from like http://www.codeproject.com/KB/android/AndroidTabs.aspx
and apply on gate.java
Below is my code.
Code: Select all
public class gtsmobile extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);       
        Chk_Login();
    }
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu, menu);       
        return true;
    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.mnugts:         
               setContentView(R.layout.main);
                break;
            case R.id.mnutracking:                    
               //setContentView(R.layout.gate);
               gate gt = new gate();
                break;
            case R.id.mnuexit:
               setContentView(R.layout.login);
                break;
        }       
       return true;
    }   
public void Chk_Login() {       
      Button launch = (Button)findViewById(R.id.login_button);      
      launch.setOnClickListener( new OnClickListener(){   
      public void onClick(View viewParam){                   
                      EditText usernameEditText = (EditText) findViewById(R.id.txt_username);
                     EditText passwordEditText = (EditText) findViewById(R.id.txt_password);              
                      String sUserName = usernameEditText.getText().toString();
                      String sPassword = passwordEditText.getText().toString();                
                      if(sUserName.length() == 0 || sPassword.length() == 0){                                   
                      ShowOKAlert();
                      }else{   setContentView(R.layout.main);  }                                  
                      }
                 }
      }); // end of launch.setOnclickListener      
   }
   
void ShowOKAlert(){
   AlertDialog alertDialog = new AlertDialog.Builder(this).create();
           alertDialog.setTitle("Login Fail");
          alertDialog.setMessage("Please Enter UserName and Password");
          alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int which) { }
   });
           alertDialog.setIcon(R.drawable.icon);
           alertDialog.show();
   }
}

Please advice me thanks.
winzone
Freshman
Freshman
 
Posts: 2
Joined: Wed Dec 29, 2010 9:19 am

Top

Return to General

Who is online

Users browsing this forum: No registered users and 3 guests