public class MainActivity extends Activity implements OnClickListener {
Button btn,btn1;
String n,m;
EditText t1,t2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
t1 = (EditText) findViewById(R.id.editText1);
t2 = (EditText) findViewById(R.id.editText2);
n= t1.getText().toString();
m = t2.getText().toString();
btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(this);
btn1 = (Button) findViewById(R.id.button2);
btn1.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.button1:
if(n.equalsIgnoreCase("subbu")&&m.equalsIgnoreCase("12345")){
Toast.makeText(this, "WELCOME",Toast.LENGTH_LONG).show();
}
break;
default:
if(n.equalsIgnoreCase("pani")&&m.equalsIgnoreCase("12345")){
Toast.makeText(this, "Hi subbu",Toast.LENGTH_LONG).show();
MediaPlayer myplayer;
myplayer = MediaPlayer.create(this, R.raw.alimba);
myplayer.start();
}
break;
}
}
}
我正在使用上面的代码,但没有得到输出我是初学者我想获得editText的文本并想与if语句中的其他文本进行比较谁能帮我做?