質問

ボタンが付いたTextViewerアクティビティがあり、クリックするとリスト付きのAlertDialogをポップアップしたいと思います。私はこれに従いました リンク しかし、それは機能しません(ポップアップはありません)。文脈は間違っていると思います。次のコードを使用しました。

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.resources);
    ImageButton btnlist = (ImageButton)findViewById(R.id.list);
    btnlist.setOnClickListener(new View.OnClickListener() {
             public void onClick (View v){                  

              if (Vars.bookchapter>1){
               final CharSequence[] items = {"Red", "Green", "Blue"};
               Context mContext = getBaseContext();
               AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
               builder.setTitle("Pick a color");
               builder.setItems(items, new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int item) {
                       Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
                   }
               });
               AlertDialog alert = builder.create();
              }else{
               //Nothing
              }
             }});         
     }
        }
役に立ちましたか?

解決

あなたは電話していません show() 方法。これを行う:

AlertDialog alert = builder.create();
alert.show();
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top