Open another event in Android using a button

I must be doing something wrong. I have this code in the first activity:

package com.Trenton.waziapp;



import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class WaziLoginScreen extends Activity implements OnClickListener{

EditText etUsername, etPassword;
Button bLogin;
Class ourClass;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.wazi_login_screen);

    etUsername = (EditText) findViewById(R.id.etUsername);
    etPassword = (EditText) findViewById(R.id.etPassword);
    bLogin = (Button) findViewById(R.id.bLogin);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.wazi_login_screen, menu);
    return true;
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch(v.getId()){
    case R.id.bLogin:

        Intent a = new Intent(WaziLoginScreen.this, ProfileScreen.class);
        startActivity(a);
        break;

    }
}

      

} What am I doing wrong here above to open another activity, ProfileScreen?

My manifest file contains an activity record like this -

    <activity
        android:name=".ProfileScreen"
        android:label="@string/title_activity_profile_screen">
    </activity>

      

+3


source to share


3 answers


You forgot to set onclickListener ... try this



yourButtonObject.setOnClickListener(this);

      

+4


source


write the following code in the OnCreate method inside your WaziLoginScreen class-

yourButtonObject.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        Intent a = new Intent(WaziLoginScreen.this, ProfileScreen.class);
        startActivity(a);
    }
});

      



thats it.

+3


source


Use the following code.

package com.Trenton.waziapp;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class WaziLoginScreen extends Activity {

EditText etUsername, etPassword;
Button bLogin;
Class ourClass;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.wazi_login_screen);

    etUsername = (EditText) findViewById(R.id.etUsername);
    etPassword = (EditText) findViewById(R.id.etPassword);
    bLogin = (Button) findViewById(R.id.bLogin);

    bLogin.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        Intent a = new Intent(WaziLoginScreen.this, ProfileScreen.class);
        startActivity(a);
    }
 }); 
 }

          @Override
           public boolean onCreateOptionsMenu(Menu menu) {
                  // Inflate the menu; this adds items to the action bar if it is present.
                  getMenuInflater().inflate(R.menu.wazi_login_screen, menu);
                 return true;
          }

}

      

Thats it..enjoy friend.

+1


source







All Articles