【问题标题】:Inflating view inside an alert dialog在警报对话框中膨胀视图
【发布时间】:2012-09-24 14:30:55
【问题描述】:

我需要问我应该如何在警报对话框中为三个按钮充气。基本上可以使用列表视图,当用户长按列表项时,应该会出现一个警告对话框,该对话框应该有编辑、删除和其他一些按钮,这些按钮应该在按下时执行它们的任务,我真的很感激,如果有人能告诉我我应该如何用按钮填充警报对话框。谢谢

【问题讨论】:

    标签: android


    【解决方案1】:

    无需两次发明轮子.. 它称为上下文菜单: http://developer.android.com/guide/topics/ui/menus.html

    【讨论】:

      【解决方案2】:

      如果您使用 AlertDialog.Buider,您可以添加三个按钮。

      new AlertDialog.Builder(this)
          .setPositiveButton("Edit", new OnClickListener()
              {
                  // Code Here
              })
          .setNeutralButton("Delete", new OnClickListener()
              {
                  // Code Here
              })
          .setNegativeButton("Delete", new OnClickListener()
              {
                  // Code Here
              })
          .create()
          .show();
      

      【讨论】:

        【解决方案3】:

        你可以使用上下文菜单,像这样:

        final OnCreateContextMenuListener occml = new OnCreateContextMenuListener() {
        
            @Override
            public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
            {
                AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
                menu.setHeaderTitle(pi.getBrowserIdentifier());
                menu.add(R.id.actionBarMenu_Settings, R.string.one, 1, getString(R.string.one));
                menu.add(R.id.actionBarMenu_Settings, R.string.two, 2, getString(R.two));
                menu.add(R.id.actionBarMenu_Settings, R.string.three, 3, getString(R.string.three));
            };
        _listView= (ListView) findViewById(R.id.list);
        _listView.setOnCreateContextMenuListener(occml);
        

        【讨论】:

          【解决方案4】:

          我就是这样,你也可以

              AlertDialog.Builder builder = new AlertDialog.Builder(this);
              builder.setTitle("Seçenekler");
              builder.setAdapter( /*#your adapter here#*/, new DialogInterface.OnClickListener() {
          
                                  @Override
                                  public void onClick(DialogInterface dialog, int which) {
          
          //do something
                                  }
                              });
          

          【讨论】:

            【解决方案5】:

            下一个代码在自定义对话框类中捕获视图覆盖 setView 扩展 alertdialog:

            class example extends Activity{
            
            
            private void onClick_show_dialog( View v )
            {
            
            
                LayoutInflater lainf = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                final View frmFileSystem = lainf.inflate(R.layout.dlg_filesystem, (ViewGroup) findViewById(R.id.lilaFileSystem));
            
                dlg_filesystem = new DlgFileSystem(this);
                dlg_filesystem.setView(frmFileSystem);
                dlg_filesystem.setCancelable(true);
                dlg_filesystem.setButton( 'aceptar' , new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialog, int which )
                {
                    alert( dlg_filesystem.prueba );
                }});
                dlg_filesystem.setButton2( 'cancelar' , new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialog, int which )
                {
                }});
                dlg_filesystem.show();
            }
            
            }
            

            public class DlgFileSystem extends AlertDialog{
            public String prueba;
            private Context context;
            private View frmFileSystem;
            
            public DlgFileSystem(Context context)
            { 
                super(context);
                this.context = context;
            }
            
            @Override
            public void setView( View frmFileSystem )
            {
                super.setView(frmFileSystem);
                this.frmFileSystem = frmFileSystem;
                TextView txprueba = (TextView)frmFileSystem.findViewById(R.id.txPrueba);
                txprueba.setText("adios");
            }   
            }
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2021-01-06
              • 1970-01-01
              相关资源
              最近更新 更多