[英]Alert Dialog Box Not Showing Android in list Activity
我正面臨一個問題。 我有一個擴展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,它工作正常。 對於Get Button我已經顯示了一個對話框,它進一步要求用戶做某事,但我面臨的問題是對話框沒有出現,我不知道為什么?
你忘了,寫行
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();
}
調用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 = new AlertDialog.Builder(QuestionListActivity.this).create(); //使用此行代替此行
AlertDialog getSurveyAlert = new AlertDialog.Builder(QuestionListActivity .this).show();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.