我不知道为什么它不起作用。无论我在编辑文本上写什么,它总是说同样的事情:“名字”+名称+“已经存在”。我只是不知道问题是什么。
public class AddScreen extends AppCompatActivity {
EditText first_name,last_name;
String first,last;
Button add;
Context ctx=this;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_screen);
first_name=(EditText)findViewById(R.id.firstname);
last_name=(EditText)findViewById(R.id.lastname);
add=(Button)findViewById(R.id.save);
first = first_name.getText().toString();
last = last_name.getText().toString();
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DataBaseOperation DB = new DataBaseOperation(ctx);
Cursor CR= DB.getInformation(DB);
CR.moveToFirst();
boolean status= false;
String NAME="";
do {
if(first.equals(CR.getString(0)) && (last.equals(CR.getString(1))))
{
status=true;
NAME=CR.getString(0)+" "+CR.getString(1);
}
}while (CR.moveToNext());
if(status)
{
Toast.makeText(getBaseContext(),"THE NAME "+NAME+"ALREADY EXIST",Toast.LENGTH_LONG).show();
finish();
}
else
{
DB.putInformation(DB, first, last);
Toast.makeText(getBaseContext(),"NEW PLAYER CREATED",Toast.LENGTH_LONG).show();
finish();
}
}
});
}
它的状态始终是真的。我认为问题出在这一行
if(first.equals(CR.getString(0)) && (last.equals(CR.getString(1))))
因为它总是如此。这是logcat
09-23 22:55:12.457 4417-4431/? W/EGL_emulation﹕ eglSurfaceAttrib not implemented
09-23 22:55:12.457 4417-4431/? W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa2ae4340, error=EGL_SUCCESS
09-23 22:55:12.555 4417-4431/? W/EGL_emulation﹕ eglSurfaceAttrib not implemented
09-23 22:55:12.555 4417-4431/? W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xb3f1eba0, error=EGL_SUCCESS
09-23 22:55:12.633 1508-2592/? E/Surface﹕ getSlotFromBufferLocked: unknown buffer: 0xabfb40d0
09-23 22:55:12.634 4417-4431/? E/Surface﹕ getSlotFromBufferLocked: unknown buffer: 0xabfb4a00
09-23 22:55:15.904 4417-4431/? E/Surface﹕ getSlotFromBufferLocked: unknown buffer: 0xabfb60c0