当我通过AlertDialog数据表单时,我的应用程序崩溃了

时间:2019-07-27 21:57:58

标签: android android-alertdialog

我希望我的应用在第一个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();
    }

}

0 个答案:

没有答案