何らかの理由で、2 つのテキスト ボックスに何を入力しても、一致するという応答が返されます。最初は使っ==
ていてうまくいかなかったので、切り替えてみましたif( a.equals( b ))
私はまだ立ち往生しています。
助けてください!
package net.2TextboxesStringCompare;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import android.widget.EditText;
/*
* 2TextboxesStringCompare
*/
public class Code8 extends Activity implements OnClickListener {
Button accept;
EditText numberStudents, numberStudents2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
numberStudents = new EditText(this);
numberStudents2 = new EditText(this);
// find our button in the UI by its ID
accept = (Button)findViewById(R.id.accept);
// set listeners for the button. Since our current class
// implements the OnClickListener interface
// we can simply pass the current object ("this") into
// the listener. The appropriate method will therefore
// be called when the event fires.
accept.setOnClickListener(this);
}
/* implement an event handler that responds to click events */
public void onClick(View v){
String a = numberStudents.getText().toString();
String b = numberStudents2.getText().toString();
if( a.equals( b ) )
Toast.makeText(getApplicationContext(), "Matches",
Toast.LENGTH_SHORT).show();
else
Toast.makeText(getApplicationContext(), numberStudents.getText()+" !=
"+numberStudents2.getText(), Toast.LENGTH_SHORT).show();
}
}