gpt4 book ai didi

android - 警告对话框不在列表 Activity 中显示 Android

转载 作者:行者123 更新时间:2023-11-29 16:13:26 25 4
gpt4 key购买 nike

我遇到了一个问题。我有一个扩展 listactivity 的类,它的代码是这样的:

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
}
}

在我的初始化函数中,您可以看到我有三个图像按钮,并且我已经为它们实现了 onClicklisteners。对于“设置”和“刷新”按钮,我展示了一个 Toast,它工作正常。对于“获取”按钮,我显示了一个对话框,进一步要求用户执行某些操作,但我面临的问题是该对话框没有出现,我不知道为什么?

最佳答案

你忘了,写行

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();
}

关于android - 警告对话框不在列表 Activity 中显示 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11339597/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com