我希望我的应用在第一个AlertDialog
中采用用户名形式的用户,并将其发布在第二个AlertDialog
中,但是当我添加以下代码行:txt.setText(edt.getText().toString());
时,我的应用崩溃。应该将第一个textview
上给定的edittext
更改为AlertDialog
。
EditText edt ;
TextView txt;
@Override
protected void onCreate(Bundle savedInstanceState) {
edt = (EditText) findViewById(R.id.edit_username);
txt = (TextView) findViewById(R.id.text02);
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 Alert () {
final 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) {
Alert01();
}
});
AlertDialog alert = builder.create();
alert.show();
}
public void Alert01 (){
txt.setText(edt.getText().toString());
AlertDialog.Builder builder01 = new AlertDialog.Builder(MainActivity.this,R.style.MyDialogTheme);
View v01 = LayoutInflater.from(MainActivity.this).inflate(R.layout.dialog1,null);
builder01.setView(v01);
builder01.setTitle("Congratulations ! ");
AlertDialog alert = builder01.create();
alert.show();
}
}