我在显示布局时遇到了困难。这是我的意图: 1. 用户单击按钮 2. 弹出一条消息,用户在是或否之间进行选择 3. 单击是时,将显示名为“拨号盘”的布局。
但是当我单击“是”时,它会显示“不幸的是,已停止”。谁能帮我 ?我知道这条线有问题...
ViewStub stub = (ViewStub)findViewById(R.id.dialpad);
stub.setVisibility(View.VISIBLE);
谢谢您的帮助 !
这是代码:
package com.example;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewStub;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class ExampleGUIDialogActivity extends Activity {
final Context context = this;
private Button button;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button) findViewById(R.id.buttonAlert);
// add button listener
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
// set title
alertDialogBuilder.setTitle("Your Title");
// set dialog message
alertDialogBuilder
.setMessage("Click yes to exit!")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, close
// current activity
// launch dialer
ViewStub stub = (ViewStub)findViewById(R.id.dialpad);
stub.setVisibility(View.VISIBLE);
//stub.inflate();
//View mDialerView = (View)findViewById(R.id.dtmf_twelve_key_dialer_view);
//mDialerView.bringToFront();
ExampleGUIDialogActivity.this.finish();
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
});
}
}