English 中文(简体)
alert中可变的 alert体数量?
原标题:Variable number of textedits in alertdialog in android?

Is it possible to set variable number of textedits in alertdialog? I ve tried to fill some container views such as StackView or LinearLayout dynamically but method addView is said to be not supported in AdapterView(exception). What s the solution?
Added:
I want to build alertdialog from the dynamic information.

AlertDialog.Builder alert = new AlertDialog.Builder(context);

now I can set its view like this:

alert.setView(v);

但是,只有文本意见或EditText才可以简单一些。 如果我想形成一些集装箱观点,其中可能包含各种内容,例如2个文本概览和3个版本? 我如何能够这样做? 现在,我只是单独编外文件,对它置之不理。 我能做些什么?

问题回答

为什么你们需要多少<代码>。 案文? 你可以使用一个单一渠道显示多个线。 如果你需要更复杂的事,你就可以以主题<条码>@android:风格/主题.Dialog来开展与我方言类似的活动,从而限制活动范围,使其无法涵盖整个显示区域。

<>Update:

下面是如何做类似方言的辅助性的例子:

• 复杂性。

public class ComplexDialog extends Activity {
    ...regular Activity stuff...

    protected void onCreate(Bundle savedInstanceState) {
        ...get extras from the intent, set up the layout, handle input, etc...

        LinearLayout dialogLayout = (LinearLayout) findViewById(R.id.dialogLayout);
        Display display = getWindowManager().getDefaultDisplay();
        int width = display.getWidth() > 640 ? 640 : (int) (display.getWidth() * 0.80);
        dialogLayout.setMinimumWidth(width);
        dialogLayout.invalidate();

        ...more regular stuff...
};

• 安乐施会

<activity android:name=".ComplexDialog" android:theme="@android:style/Theme.Dialog"></activity>

在用户观看方言时,EditTexts的数量是否在变化? 如果固定,而且只有时间不同,你可以为他们每人建造自己的布局Xml,然后通过开关声明决定你想要在方言中显示的排位。

可以在该法典中展示习俗警示:

// This example shows how to add a custom layout to an AlertDialog
            LayoutInflater factory = LayoutInflater.from(this);
            final View textEntryView = factory.inflate(
                    R.layout.helpdialog_main, null);
            return new AlertDialog.Builder(Main.this)
                    .setView(textEntryView)
                    .setPositiveButton(R.string.stringHelptextButtonOK,
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int whichButton) {

                                    // Popup is closed automatically, nothing
                                    // needs to be done here
                                }
                            }).create();

添加<代码>LinearLayout 劳动报酬

<代码>#onCreate(Bundle):

...
...
/*LinearLayout*/ mDlgLayout = new LinearLayout(this);
mDlgLayout.setOrientation(LinearLayout.VERTICAL);

AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Some title");
alert.setView(mDlgLayout);
alert.setNeutralButton("Regenerate", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dlg, int which) {
            // onClick will dismiss the dialog, just posting delayed
            // to pop up the dialog again & change the layout.
            mDlgLayout.postDelayed(new Runnable() {
                    public void run() {
                        alterDlgLayout();
                    }
                }, 200L);
        }
    });
/*AlertDialog*/ mDlg = alert.create();
...
...

http://www.un.org

void alterDlgLayout() {
    mDlgLayout.removeAllViews();
    Random rnd = new Random(System.currentTimeMillis());
    int n = rnd.nextInt(3) + 1;
    for (int i = 0; i < n; i++) {
        EditText txt = new EditText(this);
        txt.setHint("Some hint" + rnd.nextInt(100));
        mDlgLayout.addView(txt);
    }
    mDlgLayout.invalidate();
    mDlg.show();
}

http://www.un.org/Depts/DGACM/index_french.htm

alterDlgLayout();

http://www.un.org/Depts/DGACM/index_french.htm

mDlg.dismiss();

最容易的方法是,在你的方言制作方法中,将这一守则用于建立方言:

AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Some title");
ViewGroup final mainLayout = getLayoutInflater().inflate(R.layout.the_custom_holder);
final EditText[] editors = new EditText[requiredItemCount];
for (int i = 0; i < requiredItemCount; i++) {
   View inputter = getLayoutInflater().inflate(R.layout.the_custom_line);
   editors[i] = inputter.findViewById(R.id.editorId);
}

alert.setPositiveButton(R.string.stringHelptextButtonOK,
   new DialogInterface.OnClickListener() {
   public void onClick(DialogInterface dialog, int whichButton) {
      // Accessing one of the edittexts
      String requiredText = editors[3].getText().toString();
      // TODO Do stuff with result
   }
alert.setView(mDlgLayout);
alert.create().show();




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签