Multiple - multiple choice dialogs/activities, questionnaire, one question at the time

by John Smith » Tue, 27 Apr 2010 05:04:51 GMT


Sponsored Links
 Hi there,

I am new at developing for android, so bear with me (and my ignorance).

I have tried to make a series of dialogs, like a questionnaire, that the
user needs to answers a series of questions selecting one or more
checkboxes. I can do one, just fine, but when I try to make more than one
question (lets say 10), it does not show, or show all the dialogs. I tried
using dialogs or new acitivities.

So, my problem is I have multiple questions, one to be presented each time,
and I need to wait for one to be responded so I can ask the next one. How do
I accomplish this?

My first attempt was with a dialog box... but obviously it got all the boxes
stacked in each other:

[code]
 for (int i = 0; i < questions.size(); i++) {

final int counter = i;
 int size = questions.size();
CharSequence[] itemsBuilder = new CharSequence[size];
 boolean[] bitemsBuilder = new boolean[size];

for (int j = 0; j < questions(i).getPossibleAnswers().size(); j++) {
 itemsBuilder[j] = quastions(i).getPossibleAnswers().get(j);
bitemsBuilder[j] = false;
 }

final CharSequence[] items = itemsBuilder;
final boolean[] bitems = bitemsBuilder;
 AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Choose the answer for "
 + question.get(i).getQuestion();
builder.setMultiChoiceItems(items, bitems,
 new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int item,
 boolean choice) {
Log.d("choice", "" + item + " " + choice);
 Toast.makeText(getApplicationContext(),
items[item], Toast.LENGTH_SHORT).show();
 }
});
builder.setPositiveButton("next",
 new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
 dialog.dismiss();
}
});

AlertDialog alert = builder.create();
alert.show();
}
[/code]

Regards,
John Romero

--



Other Threads

1. Retrieving GRP Coordinates, getting errors with getLastKnownLocation and requestLocationUpdates

I tried the below code and it s working fine

Criteria c = new Criteria();
c.setAccuracy(Criteria.ACCURACY_FINE);
        locationMgr = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
            bestP = locationMgr.getBestProvider(c, true);
                isGpsEnabled = locationMgr.isProviderEnabled(bestP);

                if (isGpsEnabled)
                {
                         Location location =
locationMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                        locationMgr.requestLocationUpdates(bestP, 100, 1, 
gpsListener);
                }

Try this..........

REGARDS,

SREEHARI

-- 

2. Audio input from Bluetooth

Hi,

if I understand correctly, getting audio input from a Bluetooth mic/headset,
using say AudioRecord, is not supported. Is this right?

--
  Olivier

-- 

3. SOLD ! WTS: HTC Desire BNIB only 1 unit

4. Odp: A simplest Application access "Content Provider"

5. Title bar display

6. troubles reading other apps config files

7. When I override Adapter.isEnabled() the ListView divider isn't displayed