Note that there are some explanatory texts on larger screens.

plurals
  1. POAlertDialog, ListView with simpleAdapter and onItemClickListener
    primarykey
    data
    text
    <p>I have an AlertDialog with ListView and I can't understant how to get checked items... In AlertDialog i create view in code. Solve my problems please.</p> <p>AlertDialog. WORK CORRECT :</p> <pre><code> 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; } } </code></pre> <p>Some method from Main Class (extends Activity):</p> <pre><code> private ListView createListViewForAddBtnDialog(){ LinkedHashMap&lt;String, String&gt; 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&lt;Map&lt;String,String&gt;&gt;(cc.getCount()); int btnIdIndex = cc.getColumnIndex(CalcDBHelper.BTN_ID); do{ mapOfBtn = new LinkedHashMap&lt;String, String&gt;(); mapOfBtn.put(ActivityMain.btnId, getBtn.getBtnTextViaId(cc.getInt(btnIdIndex))); listOfBtn.add(mapOfBtn); } while(cc.moveToNext()); } for(int i = 0; i &lt; 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&lt;?&gt; parent, View view, int position, long id) { Log.d(ActivityMain.LOG_TAG, "!!!!!!! - "); // never call :((( } }); return lstViewBtnAdd; } </code></pre> <p>I call my AlertDialog like this:</p> <pre><code> myDialog.setViewForAddBtnView(createListViewForAddBtnDialog()); myDialog.showDialog(DIALOG_ADD_BUTTONS, getResources().getString(R.string.dialogAddBtnWhereToAdd), this, this, null, orient); </code></pre> <p>and it look like</p> <p><a href="https://www.dropbox.com/s/r2hqb9a9nt9g4hm/alertDlg.png" rel="nofollow">https://www.dropbox.com/s/r2hqb9a9nt9g4hm/alertDlg.png</a> (cant attach images)</p> <p>but when i try to chose any elements (checkBoxes) - nothing happens... help please.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload