我想在单击按钮后打开一个自定义对话框。XML中按钮的代码为:
<Button
android:id="@+id/Button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/BorderMargin"
android:layout_marginRight="@dimen/BorderMargin"
android:background="#D2D2D2"
android:onClick="openDialog1"
android:padding="17dip"
android:text="@string/ButtonAdd" />
点击后,按钮打开方法“openDialog1”:
public void openDialog1(View view) {
final Dialog dialog = new Dialog(this.getApplicationContext());
dialog.setContentView(R.layout.dialogbrand_layout);
dialog.setTitle("Hello");
TextView textViewUser = new TextView(getApplicationContext());
textViewUser = (TextView) findViewById(R.id.textBrand);
textViewUser.setText("Hi");
dialog.show();
}
我尝试执行此操作,但 textViewUser.setText 上的应用程序崩溃
有任何想法吗?