-1

我想在单声道中为 android 使用多选微调器。我想将国家绑定到微调器现在在普通微调器中有带有单选按钮的标签。但我想要带有复选框的标签。

谁能帮帮我吗。

AlertDialog.Builder alt_bld = new AlertDialog.Builder(
        CareCardActivity.this);
alt_bld.setTitle("Select Recepients");
alt_bld.setMultiChoiceItems(tempname, new boolean[tempname.length] , new DialogInterface.OnMultiChoiceClickListener() {

    public void onClick(DialogInterface dialog, int which,
            boolean isChecked) {
        // TODO Auto-generated method stub

    }
});
alt_bld.setPositiveButton("Ok", new DialogInterface.OnClickListener() {

    public void onClick(DialogInterface dialog, int which) {

        // TODO Auto-generated method stub
        ListView list = ((AlertDialog) dialog).getListView();

        Log.v("LIST COUNT:: ", ""+list.getCount());
        for (int i = 0; i < list.getCount(); i++) {
            boolean checked = list.isItemChecked(i);

            if (checked) {
                sb.append(contactNumber[i]).append(";");
            }
        }
        sb = sb.replace(
                sb.length() - 1,
                sb.length(), "");
        txtPhoneNo.setText(sb.toString());
    }
});

alt_bld.setNegativeButton("Cancel",
        new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub

            }
        });

AlertDialog alert = alt_bld.create();
alert.show();

我已经在 Eclipse 中尝试过这段代码,它在其中运行良好,但我想在 C# 中为 Mono 开发做它。

4

1 回答 1

0

单击按钮时调用此函数

ShowDialog(DIALOG_MULTIPLE_CHOICE); 

添加以下代码

protected override Dialog OnCreateDialog(int id)
    {
        switch (id) {
        case DATE_DIALOG_ID:
            return new DatePickerDialog(this, OnDateSet, date.Year, date.Month - 1, date.Day);



        case DIALOG_MULTIPLE_CHOICE: {
            var builder = new AlertDialog.Builder (this);
            //          builder.SetIcon (Resource.Drawable.ic_popup_reminder);
            builder.SetTitle ("Select Country");
            builder.SetMultiChoiceItems (countryName, new bool[countryName.Length], MultiListClicked);

            builder.SetPositiveButton ("ok", OkClicked);
            builder.SetNegativeButton ("Cancel", CancelClicked);

            return builder.Create ();
        }
        }
        return null;
    }
    private void MultiListClicked (object sender, DialogMultiChoiceClickEventArgs e)
    {
        Console.WriteLine ("countryMultiListClicked");
        if (e.IsChecked) {
            mSelectedItems.Add (countryName [(int)e.Which]);
            mSelectedItemsID.Add (countryID [(int)e.Which]);
        }
        else if (mSelectedItems.Contains(countryName [(int)e.Which]))
        {
            mSelectedItems.Remove(countryName [(int)e.Which]);
            mSelectedItemsID.Remove(countryID [(int)e.Which]);
        }
    }
    private void OkClicked (object sender, DialogClickEventArgs e)
    {
        Console.WriteLine ("countryOkClicked");

        String listString = "";
        for (int i =0; i<mSelectedItems.Count; i++) {
            listString += mSelectedItems [i] + ",";
        }
        if (listString.Length > 0) {
            listString = listString.Remove (listString.Length - 1);
        }
        et_country.Text = listString;

        listStringId = "";
        for (int i =0; i<mSelectedItemsID.Count; i++) {
            listStringId += mSelectedItemsID [i] + ",";
        }
        if (listStringId.Length > 0) {
            listStringId = listStringId.Remove (listStringId.Length - 1);
        }
        Console.WriteLine (listStringId);
    }
    private void CancelClicked (object sender, DialogClickEventArgs e)
    {
        Console.WriteLine("countryCancelClicked");
    }

这很好用........!

于 2013-02-05T11:44:25.197 回答