1

我正在将我的多选复选框对话框转换为来自公共属性和公共类(所以我可以从任何地方拉它)。

但是,通常当我在课堂上做某事时,我可以使用whatever.ID 和whatever.Name,我猜只是一个普通的多维数组。但是在这种情况下我无法弄清楚语法。

这是我的自定义类:

package com.directenquiries.assessment.tool.Globals;

public class clsNameID {
    public String Name;
    public String ID;

}

这是创建数组的内容:

public static List<clsNameID> assetHelperTypes(){
    Log.e("Asset Helper Types:", "Started");
    clsNameID AssetDetails = null;
    List<clsNameID> mHelperNames = new ArrayList<clsNameID>();
    File dbfile = new File(Global.currentDBfull); 

    SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbfile, null);
    Cursor f = db.rawQuery("select * from assetobservationtypes", null);  
    Log.e("Asset Helper Types:", "Cursor run");

    if(f.getCount() > 0) {
        f.moveToFirst();
           while(!f.isAfterLast()) {
               AssetDetails     = new clsNameID();
               AssetDetails.ID = f.getString(f.getColumnIndex("AssetObsID"));
               AssetDetails.Name = f.getString(f.getColumnIndex("Observation"));
               mHelperNames.add(AssetDetails);
               Log.e("Found Item:", AssetDetails.Name);
                f.moveToNext();
           }
    }


    f.close();

    return mHelperNames;
}

这是我尝试使用数组的地方:

public void addCondition(View view){

          List<clsNameID> mHelperNames = DBFunctions.assetHelperTypes();

            final List<Integer> mSelectedItems = new ArrayList<Integer>();

            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("My Title")
                    .setMultiChoiceItems(mHelperNames.toArray(new CharSequence[mHelperNames.size()]), null,
                            new DialogInterface.OnMultiChoiceClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog,
                                        int which, boolean isChecked) {
                                    if (isChecked) {

                                        mSelectedItems.add(which);
                                    } else if (mSelectedItems.contains(which)) {

                                        mSelectedItems.remove(Integer
                                                .valueOf(which));
                                    }   
                                }
                            })



   .setPositiveButton("Save", new DialogInterface.OnClickListener() {
                   @Override
                   public void onClick(DialogInterface dialog, int id) {
                        //Create onlcick method
                   }
               })
               .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                   @Override
                   public void onClick(DialogInterface dialog, int id) {
                        //Create onlcick method
                   }
               });
        builder.show();

}

我想我真正需要做的是.setMultiChoiceItems(mHelperNames.toArray.Name(new CharSequence[mHelperNames.size()])

但显然这行不通。如何将名称值分配给我的 setMultiChoiceItems 数组?

汤姆

4

0 回答 0