警报对话框未在列表活动中显示Android
我面临一个问题。 我有一个扩展listactivity的类,其代码如下:警报对话框未在列表活动中显示Android,android,Android,我面临一个问题。 我有一个扩展listactivity的类,其代码如下: public class QuestionListActivity extends ListActivity { //Members private ImageButton bntRefresh; private ImageButton bntSettings; private ImageButton bntGetSurveys; /** Called when the activity is first crea
public class QuestionListActivity extends ListActivity
{
//Members
private ImageButton bntRefresh;
private ImageButton bntSettings;
private ImageButton bntGetSurveys;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.surveylist);
initialize();
currentSurveys=new SurveyList();
}
private void initialize()
{
bntRefresh= (ImageButton) findViewById(R.id.ibtnRefresh);
bntRefresh.setImageResource(R.drawable.refresh);
bntRefresh.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(SurveyListActivity.this, "This will refresh the survey list.", Toast.LENGTH_SHORT).show();
}
});
bntSettings= (ImageButton) findViewById(R.id.ibtnSettings);
bntSettings.setImageResource(R.drawable.settings);
bntSettings.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(SurveyListActivity.this, "This will open the settings.", Toast.LENGTH_SHORT).show();
}
});
bntGetSurveys= (ImageButton) findViewById(R.id.ibtnGetSurveys);
bntGetSurveys.setImageResource(R.drawable.getsurvey);
bntGetSurveys.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
AlertDialog getSurveyAlert = new AlertDialog.Builder(QuestionListActivity .this).create();
getSurveyAlert.setTitle("Enter QR Code");
getSurveyAlert.setMessage("Choose a source");
getSurveyAlert.setButton("Camera", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
getSurveyAlert.setButton2("text", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
}
});
}
class SurveyAdapter extends ArrayAdapter<Survey>
{
//-- code here for adapter
}
}
在我的initialize函数中,您可以看到我有三个ImageButton,并为它们实现了onClicklisteners。
对于设置和刷新按钮,我已经展示了一个祝酒词,它工作正常。
对于“获取”按钮,我显示了一个对话框,它进一步要求用户执行某些操作,但我面临的问题是对话框没有出现,我不知道为什么?您忘记了,请写一行
getSurveyAlert.show();
试试这个
bntGetSurveys.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
AlertDialog getSurveyAlert = new AlertDialog.Builder(QuestionListActivity .this).create();
getSurveyAlert.setTitle("Enter QR Code");
getSurveyAlert.setMessage("Choose a source");
getSurveyAlert.setButton("Camera", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
getSurveyAlert.setButton2("text", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
getSurveyAlert.create().show();
}
你忘了写一行
getSurveyAlert.show();
试试这个
bntGetSurveys.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
AlertDialog getSurveyAlert = new AlertDialog.Builder(QuestionListActivity .this).create();
getSurveyAlert.setTitle("Enter QR Code");
getSurveyAlert.setMessage("Choose a source");
getSurveyAlert.setButton("Camera", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
getSurveyAlert.setButton2("text", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
getSurveyAlert.create().show();
}
呼叫显示方法
@Override
public void onClick(View v)
{
AlertDialog getSurveyAlert = new AlertDialog.Builder(QuestionListActivity .this).create();
getSurveyAlert.setTitle("Enter QR Code");
getSurveyAlert.setMessage("Choose a source");
getSurveyAlert.setButton("Camera", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
getSurveyAlert.setButton2("text", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
getSurveyAlert.create().show();
}
});
呼叫显示方法
@Override
public void onClick(View v)
{
AlertDialog getSurveyAlert = new AlertDialog.Builder(QuestionListActivity .this).create();
getSurveyAlert.setTitle("Enter QR Code");
getSurveyAlert.setMessage("Choose a source");
getSurveyAlert.setButton("Camera", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
getSurveyAlert.setButton2("text", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
getSurveyAlert.create().show();
}
});
AlertDialog getSurveyAlert=新建AlertDialog.BuilderQuestionListActivity.this.create; //用这行代替这行
AlertDialog getSurveyAlert=新建AlertDialog.BuilderQuestionListActivity.this.show AlertDialog getSurveyAlert=新建AlertDialog.BuilderQuestionListActivity.this.create; //用这行代替这行
AlertDialog getSurveyAlert=新建AlertDialog.BuilderQuestionListActivity.this.show 谢谢,我想我现在有点搞砸了。。只是忘了这么简单的事。谢谢,我想我现在有点搞砸了。。只是忘了这么简单的事。谢谢,我想我现在有点搞砸了。。只是忘了这么简单的事。谢谢,我想我现在有点搞砸了。。忘了这么简单的事。