Home > Mobile >  Android studio button function keys one click quit the simulator, urgent urgent!!!!!!
Android studio button function keys one click quit the simulator, urgent urgent!!!!!!

Time:09-17

Mainactivity. Java

Package com. Example. Direction;

The import androidx. Appcompat. App. AppCompatActivity;


The import android. Content. ContentValues;
The import android. Database. Cursor;
The import android. Database. Sqlite. SQLiteDatabase;
The import android. OS. Bundle;
The import android. View. The view;
The import android. Widget. The Button;
The import android. Widget. The EditText;
The import android. Widget. TextView;
The import android. Widget. Toast;


Public class MainActivity extends AppCompatActivity implements the View. An OnClickListener {
MyHelper MyHelper;
Private EditText mEtName;
Private EditText mEtPhone;
Private TextView mTvShow;
Private Button mBtnAdd;
Private Button mBtnQuery;
Private Button mBtnUpdate;
Private Button mBtnDelete;
@ Override
Protected void onCreate (Bundle savedInstanceState) {
Super. OnCreate (savedInstanceState);
The setContentView (R.l ayout. Activity_main);
MyHelper=new myHelper (this);
The init ();
}


Private void init () {
MEtName=(EditText) the findViewById (R.i d.e t_name);
MEtPhone=(EditText) the findViewById (R.i d.e t_phone);
MTvShow=(TextView) the findViewById (R.i which v_show);

MBtnAdd=(Button) the findViewById (R.i db tn_add);
MBtnQuery=(Button) the findViewById (R.i db tn_query);
MBtnUpdate=(Button) the findViewById (R.i db tn_update);
MBtnDelete=(Button) the findViewById (R.i db tn_delete);



MBtnAdd. SetOnClickListener (this);
MBtnDelete. SetOnClickListener (this);
MBtnUpdate. SetOnClickListener (this);
MBtnQuery. SetOnClickListener (this);
}

@ Override
Public void onClick (View v) {
String name;
String phone;
SQLiteDatabase db.
ContentValues values;
The switch (v.g etId ()) {
Case R.i db tn_add:
Name=mEtName. GetText (). The toString ();
Phone=mEtPhone. GetText (). The toString ();
The db=myHelper. GetReadableDatabase ();
Values=new ContentValues ();
Values. The put (" name ", name);
Values. The put (" phone ", phone);
The insert (" information ", null values);
Toast. MakeText (this, "information have been added," Toast. LENGTH_SHORT), show ();
The close ();
break;
Case R.i db tn_query:
The db=myHelper. GetReadableDatabase ();
Cursor Cursor=db. Query (" information ", null, null, null, null, null, null);
If (cursor. GetCount ()==0) {
MTvShow. SetText (" ");
Toast. MakeText (this, "no data", Toast. LENGTH_SHORT), show ();
} else {
Cursor. MoveToFirst ();
MTvShow. SetText (" Name: "+ cursor. Get string (1) +"; Tel: "+ cursor. Get string (2));
}
While (cursor. MoveToNext ()) {
MTvShow. Append (" \ n "+" Name: "+ cursor. Get string (1) +"; Tel: "+ cursor. Get string (2));
}
Cursor. The close ();
The close ();
break;

Case R.i db tn_update:
The db=myHelper. GetWritableDatabase ();
Values=new ContentValues ();
Values. The put (" phone ", phone=mEtPhone getText (), toString ());
The update (" information ", values, "name=?" , new String [] {mEtName. GetText (), toString ()});
The close ();
break;

Case R.i db tn_delete:
The db=myHelper. GetWritableDatabase ();
The delete (" information ", null, null);
Toast. MakeText (this, "information has been deleted", Toast. LENGTH_SHORT), show ();
MTvShow. SetText (" ");
The close ();
break;
}
}
}

CodePudding user response:

Look at the log log, log will be able to tell you why out of the race

CodePudding user response:

The error log, if not, can't help you
  • Related