2

ListView가있는 AlertDialog가 있는데 체크 된 항목을 가져 오는 방법을 이해할 수 없습니다. AlertDialog에서 코드보기를 만듭니다. 내 문제를 해결하십시오.SimpleAdapter 및 onItemClickListener가있는 ListView AlertDialog

AlertDialog. 올바른 WORK :

 public class MyDialog { 
...... 
AlertDialog.Builder adb; 
private Dialog onCreateDialog(int id, Context context) { 
    workWithDB = new WorkWithDB(context); 
    adb = new AlertDialog.Builder(context); 
    switch (id) { 
    case ActivityMain.DIALOG_ADD_BUTTONS: 
      adb.setTitle(R.string.app_name); 
      adb.setIcon(android.R.drawable.ic_input_add); 
      adb.setPositiveButton(R.string.dialogAddBtn, myClickListener); 
      adb.setNeutralButton(R.string.dialogConfirmChangesCancel, myClickListener); 
      adb.setView(addBtnView()); 
     return adb.create(); 
    } 
     return onCreateDialog(id, context); 
    } 
OnClickListener myClickListener = new OnClickListener() { 
    public void onClick(DialogInterface dialog, int which) { 
    // Main.editor.putBoolean("continue", true); 
    // Main.editor.commit(); 
     switch (id) { 
     case ActivityMain.DIALOG_ADD_BUTTONS: 
      // some code 
      break; 
     } 

    } 
    }; 
    public void showDialog(int id, Context context /* some parametres*/){ 
     onCreateDialog(id, context); 
     adb.show();  
    } 
    protected void setViewForAddBtnView(ListView lstView){ 
     this.lstView = lstView; 
    } 
    protected View addBtnView(){ 
     LinearLayout llMain = new LinearLayout(context); 
     RadioGroup rGroupWhereAddBtns = new RadioGroup(context); 
     RadioButton top = new RadioButton(context), bottom = new RadioButton(context); 
     top.setText(context.getResources().getString(R.string.addBtnTop)); 
     bottom.setText(context.getResources().getString(R.string.addBtnBottom)); 
     rGroupWhereAddBtns.setOrientation(RadioGroup.HORIZONTAL); 
     rGroupWhereAddBtns.addView(top); 
     rGroupWhereAddBtns.addView(bottom); 

     llMain.setOrientation(LinearLayout.VERTICAL); 
     llMain.addView((new MyMsg()).view(context, " " + message, Color.BLACK, ActivityMain.messageTextSize + 2, Gravity.LEFT));  
     llMain.addView(rGroupWhereAddBtns); 
     llMain.addView(lstView); 
     return llMain; 
    } 

    } 

메인 클래스에서 어떤 방법 (활동을 확장) :

  private ListView createListViewForAddBtnDialog(){ 
    LinkedHashMap<String, String> mapOfBtn; 
    SimpleAdapter adapterAddBtnDialog; 
    ListView lstViewBtnAdd = new ListView(this); 
    SQLiteDatabase dbBtn = calcDbHelper.getReadableDatabase();   
    Cursor cc = dbBtn.query(CalcDBHelper.TABLE_BUTTONS, null, "profileName = 'unnamed' and orientation = '"+ orient + "' and canBeAdded = 1", null, null, null, null);   
    //try { 
    if (cc.moveToFirst()){ 
     //(new WorkWithDB(context)).showButtonsTable(); 
     Log.d(ActivityMain.LOG_TAG, "cursor count = " + cc.getCount()); 
     listOfBtn = new ArrayList<Map<String,String>>(cc.getCount()); 
     int btnIdIndex = cc.getColumnIndex(CalcDBHelper.BTN_ID); 
     do{ 
      mapOfBtn = new LinkedHashMap<String, String>(); 
      mapOfBtn.put(ActivityMain.btnId, getBtn.getBtnTextViaId(cc.getInt(btnIdIndex))); 
      listOfBtn.add(mapOfBtn); 
     } while(cc.moveToNext()); 
    } 
    for(int i = 0; i < listOfBtn.size(); i++){ 
     Log.d(ActivityMain.LOG_TAG, "pos " + i + " text - " + listOfBtn.get(i)); 
    } 
    adapterAddBtnDialog = new SimpleAdapter(this, listOfBtn, R.layout.dialog_add_btn_item, FROM, TO); 
    lstViewBtnAdd.setAdapter(adapterAddBtnDialog); 
    lstViewBtnAdd.setOnItemClickListener(new OnItemClickListener() { 
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
      Log.d(ActivityMain.LOG_TAG, "!!!!!!! - "); // never call :(((
     } 
    }); 
    return lstViewBtnAdd; 
} 

나는이처럼 내에 AlertDialog를 호출

 myDialog.setViewForAddBtnView(createListViewForAddBtnDialog()); 
     myDialog.showDialog(DIALOG_ADD_BUTTONS, getResources().getString(R.string.dialogAddBtnWhereToAdd), this, this, null, orient); 

하고

https://www.dropbox.com/s/r2hqb9a9nt9g4hm/alertDlg.png처럼 (캔트 이미지 첨부)

하지만 어떤 요소 (checkBoxes)를 선택하려고해도 아무 일도 일어나지 않습니다 ... 도와주세요.

답변

0

각 확인란에 수신기를 추가해야합니다. ListView의 ListView 리스너로서 textView의 경우에는 작동하지만 checkbox의 경우에는 작동하지 않습니다.

+0

thx에 대한 조언. 나는 해결책을 여기에서 찾아 냈다 - http://www.vogella.com/articles/AndroidListView/article.html –