Я хочу попросить моего пользователя ввести имя пользователя в диалоговом окне предупреждения и отобразить его во втором диалоговом окне предупреждения, которое появляется сразу после первого. Для этого я использую базы данных SQLite.
public class MainActivity extends AppCompatActivity {
Database myDB;
@Override
protected void onCreate(Bundle savedInstanceState) {
myDB = new Database(MainActivity.this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(this, getSupportFragmentManager());
ViewPager viewPager = findViewById(R.id.view_pager);
viewPager.setAdapter(sectionsPagerAdapter);
TabLayout tabs = findViewById(R.id.tabs);
tabs.setupWithViewPager(viewPager);
Alert();
}
public void Dialog() {
AlertDialog.Builder alert01 = new AlertDialog.Builder(MainActivity.this);
alert01.setTitle("Congratulations ! ");
alert01.setMessage("You've purchased the most expensive app in the world ! ");
Database myDB;
myDB = new Database(MainActivity.this);
Cursor res = myDB.getAllData();
if(res.getCount() == 0) {
// show message
showMessage("Error","Nothing found");
return;
}
StringBuffer buffer = new StringBuffer();
while (res.moveToNext()) {
buffer.append("Name :"+ res.getString(1)+"\n");
}
showMessage("Data",buffer.toString());
}
public void Alert (){
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this,R.style.MyDialogTheme);
View v = LayoutInflater.from(MainActivity.this).inflate(R.layout.dialog0,null);
builder.setMessage("Welcome ! ");
builder.setView (v);
builder.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
EditText edituser ;
edituser = (EditText) findViewById(R.id.edit_username);
boolean isInserted = myDB.DataInput(edituser.getText().toString());
if(isInserted == true)
Toast.makeText(MainActivity.this,"Data Inserted",Toast.LENGTH_LONG).show();
else
Toast.makeText(MainActivity.this,"Data not Inserted",Toast.LENGTH_LONG).show();
Dialog();
}})
.setNegativeButton("Cancel",null)
.setCancelable(false);
AlertDialog alert = builder.create();
alert.show();
}
public void showMessage(String title,String Message){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(Message);
builder.show();