3

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 get the other Activity, ProfileScreen to open?

My manifest file contains activity entry like this-

 <activity android:name=".ProfileScreen" android:label="@string/title_activity_profile_screen"> </activity> 
3
  • What is the exception post log cat Commented Feb 11, 2013 at 18:23
  • and... what happens? Is there an error message? Does the application crash? Did you try debugging? Did you try putting some log statements in to see what is getting called? Commented Feb 11, 2013 at 18:23
  • where is oncreate ...post logcat..... Commented Feb 11, 2013 at 18:25

3 Answers 3

4

You have forgot to set onclickListener... try this

yourButtonObject.setOnClickListener(this); 
Sign up to request clarification or add additional context in comments.

1 Comment

@user2046848 I haven't beg for Accept...That's why I have kept "if" condition...he said thanks that will be enough for me....
3

write following code in your 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.

4 Comments

I cant have it implement OnClickListener and use what i did above?
yes you can but than just add the line at the last in your oncreate metnod: bLogin.setOnClickListener(this); THat will also do the work. enjoy friend no tension.
@DDukesterman pls upvote as i helped. and mark answer as helpful
@shriduttkothari remove one post
0

Use this 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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.