Example usage for android.widget ArrayAdapter ArrayAdapter

List of usage examples for android.widget ArrayAdapter ArrayAdapter

Introduction

In this page you can find the example usage for android.widget ArrayAdapter ArrayAdapter.

Prototype

public ArrayAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List<T> objects) 

Source Link

Document

Constructor

Usage

From source file:edu.umich.flowfence.testapp.TestActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test);
    kvsValueField = (EditText) findViewById(R.id.kvs_value);
    shouldTaintBox = (CheckBox) findViewById(R.id.is_tainted);
    rootLayout = (RelativeLayout) findViewById(R.id.root_layout);
    sandboxCount = (Spinner) findViewById(R.id.sandbox_count);
    sandboxCountType = (Spinner) findViewById(R.id.sandbox_count_type);
    perfPassCount = (EditText) findViewById(R.id.perf_pass_count);
    taintPerfBox = (CheckBox) findViewById(R.id.perf_taint);

    // Set up adapter for sandbox count spinner
    CharSequence[] countList = new CharSequence[FlowfenceConstants.NUM_SANDBOXES + 1];
    for (int i = 0; i <= FlowfenceConstants.NUM_SANDBOXES; i++) {
        countList[i] = getResources().getQuantityString(R.plurals.sandbox_plurals, i, i);
    }//from  w  w  w.  ja va2  s  .com
    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item,
            countList);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sandboxCount.setAdapter(adapter);
    sandboxCount.setSelection(FlowfenceConstants.NUM_SANDBOXES);

    adapter = ArrayAdapter.createFromResource(this, R.array.sandbox_count_labels,
            android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sandboxCountType.setAdapter(adapter);

    setButtonsEnabled(false);
    connectToFlowfence(null);
}

From source file:com.arantius.tivocommander.SeasonPass.java

public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
    final JsonNode sub = mSubscriptionData.get(position);
    final String subType = sub.path("idSetSource").path("type").asText();
    if ("wishListSource".equals(subType)) {
        return false;
    }// w  w  w .j av  a  2 s . c  o m

    mLongClickPosition = position;

    final ArrayList<String> choices = new ArrayList<String>();
    choices.add(Explore.RecordActions.SP_MODIFY.toString());
    choices.add(Explore.RecordActions.SP_CANCEL.toString());
    final ArrayAdapter<String> choicesAdapter = new ArrayAdapter<String>(this,
            android.R.layout.select_dialog_item, choices);

    Builder dialogBuilder = new AlertDialog.Builder(this);
    dialogBuilder.setTitle("Operation?");
    dialogBuilder.setAdapter(choicesAdapter, this);
    AlertDialog dialog = dialogBuilder.create();
    dialog.show();

    return true;
}

From source file:com.code.android.vibevault.SearchScreen.java

private void launchSettingsDialog() {
    final SeekBar seek;
    final Spinner sortSpin;
    final Spinner searchSpin;
    final TextView seekValue;

    // Make the settings dialog.
    AlertDialog.Builder ad = new AlertDialog.Builder(this);
    ad.setTitle("Search Settings");
    View v = LayoutInflater.from(this).inflate(R.layout.scrollable_settings_dialog, null);
    ad.setPositiveButton("Okay.", new android.content.DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int arg1) {
        }//ww w. j  a  va  2 s  .  c  o  m
    });

    // Grab all the GUI widgets.
    seek = (SeekBar) v.findViewById(R.id.NumResultsSeekBar);
    seek.setProgress(Integer.valueOf(VibeVault.db.getPref("numResults")) - 10);
    sortSpin = (Spinner) v.findViewById(R.id.SortSpinner);
    searchSpin = (Spinner) v.findViewById(R.id.SearchSpinner);
    seekValue = (TextView) v.findViewById(R.id.SeekBarValue);
    seekValue.setText(VibeVault.db.getPref("numResults"));

    // Set the seek bar to its current value, and set up a Listener.
    seek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            seekValue.setText(String.valueOf(progress + 10));
            VibeVault.db.updatePref("numResults", String.valueOf(progress + 10));
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

    // Set up the spinner, and set up it's OnItemSelectedListener.
    ArrayAdapter<String> sortAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            VibeVault.sortChoices);
    sortAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sortSpin.setAdapter(sortAdapter);
    int sortPos = 1;
    String sortOrder = VibeVault.db.getPref("sortOrder");
    for (int i = 0; i < VibeVault.sortChoices.length; i++) {
        if (VibeVault.sortChoices[i].equals(sortOrder))
            sortPos = i;
    }
    sortSpin.setSelection(sortPos);
    sortSpin.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> arg0, View view, int arg2, long arg3) {
            int selected = arg0.getSelectedItemPosition();
            VibeVault.db.updatePref("sortOrder", VibeVault.sortChoices[selected]);
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }

    });

    ArrayAdapter<String> searchAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            VibeVault.searchChoices);
    searchAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    searchSpin.setAdapter(searchAdapter);
    int searchPos = 1;
    String searchOrder = VibeVault.searchPref;
    for (int i = 0; i < VibeVault.searchChoices.length; i++) {
        if (VibeVault.searchChoices[i].equals(searchOrder))
            searchPos = i;
    }
    searchSpin.setSelection(searchPos);
    searchSpin.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> arg0, View view, int arg2, long arg3) {
            int selected = arg0.getSelectedItemPosition();
            VibeVault.searchPref = VibeVault.searchChoices[selected];
            if (VibeVault.searchPref.equals("Artist") && artistSearchInput.getText().equals("")) {
                artistSearchInput.setHint("Search Artists...");
            } else if (VibeVault.searchPref.equals("Show/Artist Description")
                    && artistSearchInput.getText().equals("")) {
                artistSearchInput.setHint("Search Descriptions...");
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }

    });

    // Show the settings screen.
    ad.setView(v);
    ad.show();
}

From source file:com.mifos.mifosxdroid.online.LoanAccountFragment.java

private void inflateAmortizationSpinner() {
    showProgress(true);/*w ww .  j  a v  a  2 s. co m*/
    App.apiManager.getLoansAccountTemplate(clientId, productId, new Callback<Response>() {
        @Override

        public void success(final Response result, Response response) {
            /* Activity is null - Fragment has been detached; no need to do anything. */
            if (getActivity() == null)
                return;

            Log.d(LOG_TAG, "");

            final List<AmortizationType> amortizationType = new ArrayList<>();
            // you can use this array to populate your spinner
            final ArrayList<String> amortizationTypeNames = new ArrayList<String>();
            //Try to get response body
            BufferedReader reader = null;
            StringBuilder sb = new StringBuilder();
            try {
                reader = new BufferedReader(new InputStreamReader(result.getBody().in()));
                String line;
                while ((line = reader.readLine()) != null) {
                    sb.append(line);
                }
                JSONObject obj = new JSONObject(sb.toString());
                if (obj.has("amortizationTypeOptions")) {
                    JSONArray amortizationTypes = obj.getJSONArray("amortizationTypeOptions");
                    for (int i = 0; i < amortizationTypes.length(); i++) {
                        JSONObject amortizationTypeObject = amortizationTypes.getJSONObject(i);
                        AmortizationType amortization = new AmortizationType();
                        amortization.setId(amortizationTypeObject.optInt("id"));
                        amortization.setValue(amortizationTypeObject.optString("value"));
                        amortizationType.add(amortization);
                        amortizationTypeNames.add(amortizationTypeObject.optString("value"));
                        amortizationTypeIdHashMap.put(amortization.getValue(), amortization.getId());
                    }

                }
                String stringResult = sb.toString();
            } catch (Exception e) {
                Log.e(LOG_TAG, "", e);
            }
            final ArrayAdapter<String> amortizationTypeAdapter = new ArrayAdapter<>(getActivity(),
                    layout.simple_spinner_item, amortizationTypeNames);
            amortizationTypeAdapter.setDropDownViewResource(layout.simple_spinner_dropdown_item);
            sp_amortization.setAdapter(amortizationTypeAdapter);
            sp_amortization.setOnItemSelectedListener(new OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                    amortizationTypeId = amortizationTypeIdHashMap.get(amortizationTypeNames.get(i));
                    Log.d("ammortization" + amortizationTypeNames.get(i), String.valueOf(amortizationTypeId));
                    if (amortizationTypeId != -1) {

                    } else {

                        Toast.makeText(getActivity(), getString(R.string.error_select_fund), Toast.LENGTH_SHORT)
                                .show();

                    }

                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {

                }
            });

            showProgress(false);

        }

        @Override
        public void failure(RetrofitError retrofitError) {

            Log.d(LOG_TAG, retrofitError.getLocalizedMessage());

            showProgress(false);
        }
    });
}

From source file:com.github.michalbednarski.intentslab.browser.ComponentFetcher.java

@Override
void initConfigurationForm(final FetcherOptionsDialog dialog) {
    // Disable development permission checkbox if it's not available
    if (!DEVELOPMENT_PERMISSIONS_SUPPORTED) {
        dialog.findView(R.id.permission_filter_development).setEnabled(false);
    }//from   w w w  . ja v a  2s .  c o m

    // Prepare protection preset spinner
    {
        // Find current preset
        int currentPresetId = PROTECTION_PRESETS.length; // "Custom" if nothing found
        if (!testWritePermissionForProviders) {
            for (int i = 0; i < PROTECTION_PRESETS.length; i++) {
                if (protection == PROTECTION_PRESETS[i]) {
                    currentPresetId = i;
                    dialog.findView(R.id.permission_filter_details).setVisibility(View.GONE);
                    break;
                }
            }
        }

        // Fill spinner
        Spinner protectionPresetSpinner = (Spinner) dialog.findView(R.id.permission_filter_spinner);
        Activity activity = dialog.getActivity();
        protectionPresetSpinner
                .setAdapter(new ArrayAdapter<String>(activity, android.R.layout.simple_spinner_item,
                        new String[] { activity.getString(R.string.permission_filter_show_all), // 0
                                activity.getString(R.string.permission_filter_show_exported), // 1
                                activity.getString(R.string.permission_filter_show_obtainable), // 2
                                activity.getString(R.string.permission_filter_world_accessible), // 3
                                activity.getString(R.string.filter_custom) // 4
                        }));
        protectionPresetSpinner.setSelection(currentPresetId);

        // Set up spinner event
        protectionPresetSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                boolean isCustom = position == PROTECTION_PRESETS.length;
                if (!isCustom) {
                    int preset = PROTECTION_PRESETS[position];
                    dialog.setBoxChecked(R.id.permission_filter_world_accessible,
                            (preset & PROTECTION_WORLD_ACCESSIBLE) != 0);
                    dialog.setBoxChecked(R.id.permission_filter_normal, (preset & PROTECTION_NORMAL) != 0);
                    dialog.setBoxChecked(R.id.permission_filter_dangerous,
                            (preset & PROTECTION_DANGEROUS) != 0);
                    dialog.setBoxChecked(R.id.permission_filter_signature,
                            (preset & PROTECTION_SIGNATURE) != 0);
                    dialog.setBoxChecked(R.id.permission_filter_system, (preset & PROTECTION_SYSTEM) != 0);
                    dialog.setBoxChecked(R.id.permission_filter_development,
                            (preset & PROTECTION_DEVELOPMENT) != 0);
                    dialog.setBoxChecked(R.id.permission_filter_unexported,
                            (preset & PROTECTION_UNEXPORTED) != 0);
                    dialog.setBoxChecked(R.id.permission_filter_unknown, (preset & PROTECTION_UNKNOWN) != 0);
                    dialog.setBoxChecked(R.id.read_permission, true);
                }
                dialog.findView(R.id.permission_filter_details)
                        .setVisibility(isCustom ? View.VISIBLE : View.GONE);
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                // Spinner cannot have nothing selected
            }
        });
    }

    // Fill form
    dialog.setBoxChecked(R.id.system_apps, (appType & APP_TYPE_SYSTEM) != 0);
    dialog.setBoxChecked(R.id.user_apps, (appType & APP_TYPE_USER) != 0);

    dialog.setBoxChecked(R.id.activities, (type & PackageManager.GET_ACTIVITIES) != 0);
    dialog.setBoxChecked(R.id.receivers, (type & PackageManager.GET_RECEIVERS) != 0);
    dialog.setBoxChecked(R.id.services, (type & PackageManager.GET_SERVICES) != 0);
    dialog.setBoxChecked(R.id.content_providers, (type & PackageManager.GET_PROVIDERS) != 0);

    dialog.setBoxChecked(R.id.permission_filter_world_accessible,
            (protection & PROTECTION_WORLD_ACCESSIBLE) != 0);
    dialog.setBoxChecked(R.id.permission_filter_normal, (protection & PROTECTION_NORMAL) != 0);
    dialog.setBoxChecked(R.id.permission_filter_dangerous, (protection & PROTECTION_DANGEROUS) != 0);
    dialog.setBoxChecked(R.id.permission_filter_signature, (protection & PROTECTION_SIGNATURE) != 0);
    dialog.setBoxChecked(R.id.permission_filter_system, (protection & PROTECTION_SYSTEM) != 0);
    dialog.setBoxChecked(R.id.permission_filter_development, (protection & PROTECTION_DEVELOPMENT) != 0);
    dialog.setBoxChecked(R.id.permission_filter_unexported, (protection & PROTECTION_UNEXPORTED) != 0);
    dialog.setBoxChecked(R.id.permission_filter_unknown, (protection & PROTECTION_UNKNOWN) != 0);

    dialog.setBoxChecked(testWritePermissionForProviders ? R.id.write_permission : R.id.read_permission, true);
    dialog.setBoxChecked(R.id.only_providers_with_grant_uri_permission,
            includeOnlyProvidersAllowingPermissionGranting);

    dialog.setBoxChecked(R.id.metadata, requireMetaDataSubstring != null);
    dialog.setTextInField(R.id.metadata_substring, requireMetaDataSubstring);

    // Set up sections showing when their checkboxes are checked
    dialog.findView(R.id.content_provider_permission_type)
            .setVisibility(testWritePermissionForProviders ? View.VISIBLE : View.GONE);
    dialog.findView(R.id.content_provider_options)
            .setVisibility((type & PackageManager.GET_PROVIDERS) != 0 ? View.VISIBLE : View.GONE);
    ((CheckBox) dialog.findView(R.id.content_providers))
            .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    dialog.findView(R.id.content_provider_permission_type)
                            .setVisibility(isChecked ? View.VISIBLE : View.GONE);
                    dialog.findView(R.id.content_provider_options)
                            .setVisibility(isChecked ? View.VISIBLE : View.GONE);
                    if (!isChecked) {
                        dialog.setBoxChecked(R.id.read_permission, true);
                        dialog.setBoxChecked(R.id.only_providers_with_grant_uri_permission, false);
                    }
                }
            });

    dialog.findView(R.id.metadata_details)
            .setVisibility(requireMetaDataSubstring != null ? View.VISIBLE : View.GONE);
    ((CheckBox) dialog.findView(R.id.metadata))
            .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    dialog.findView(R.id.metadata_details).setVisibility(isChecked ? View.VISIBLE : View.GONE);
                    if (!isChecked) {
                        dialog.setTextInField(R.id.metadata_substring, "");
                    }
                }
            });
}

From source file:com.sssemil.sonyirremote.ir.ir.java

public void prepItemBrandArray() {
    spinner = ((Spinner) findViewById(R.id.spinner));
    localArrayList1 = new ArrayList();
    boolean edited = false;

    for (File localFile1 : new File(this.irpath).listFiles()) {
        if (localFile1.isDirectory()) {
            if (!localArrayList1.contains(localFile1.getName())) {
                localArrayList1.add(localFile1.getName());
                edited = true;/*  w  w  w  .  j  av a2 s.  com*/
            }
        }

        if (edited) {
            ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_spinner_item, localArrayList1);
            dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner.setAdapter(dataAdapter);
        }
    }
}

From source file:com.tt.jobtracker.MainActivity.java

private void SetNavigationDrawer() {
    mTitle = mDrawerTitle = getTitle();/*from   w w  w.  jav a 2s  .co m*/
    mMenuTitles = getResources().getStringArray(R.array.array_menu_main);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    // set a custom shadow that overlays the main content when the drawer
    // opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener
    mDrawerList.setAdapter(new ArrayAdapter<>(this, R.layout.drawer_list_item, mMenuTitles));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getSupportActionBar().setTitle(mTitle);
            invalidateOptionsMenu(); // creates call to
            // onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to
            // onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);
}

From source file:reportsas.com.formulapp.Formulario.java

public LinearLayout obtenerLayout(LayoutInflater infla, Pregunta preg) {
    int id;/*from w ww.  j  a  v a2s  . c o m*/
    int tipo_pregunta = preg.getTipoPregunta();
    LinearLayout pregunta;
    TextView textView;
    TextView textAyuda;
    switch (tipo_pregunta) {
    case 1:
        id = R.layout.pregunta_texto;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloPregunta);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        break;
    case 2:
        id = R.layout.pregunta_multitexto;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.mtxtTritulo);
        textAyuda = (TextView) pregunta.findViewById(R.id.mtxtAyuda);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());

        break;
    case 3:
        id = R.layout.pregunta_seleccion;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloSeleccion);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_seleccion);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        RadioGroup rg = (RadioGroup) pregunta.findViewById(R.id.opcionesUnica);
        ArrayList<OpcionForm> opciones = preg.getOpciones();
        final ArrayList<RadioButton> rb = new ArrayList<RadioButton>();

        for (int i = 0; i < opciones.size(); i++) {
            OpcionForm opcion = opciones.get(i);
            rb.add(new RadioButton(this));
            rg.addView(rb.get(i));
            rb.get(i).setText(opcion.getEtInicial());

        }
        final TextView respt = (TextView) pregunta.findViewById(R.id.respuestaGruop);
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                int radioButtonID = group.getCheckedRadioButtonId();
                RadioButton radioButton = (RadioButton) group.findViewById(radioButtonID);
                respt.setText(radioButton.getText());
            }
        });

        break;
    case 4:
        id = R.layout.pregunta_multiple;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloMultiple);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_mltiple);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        ArrayList<OpcionForm> opciones2 = preg.getOpciones();
        final EditText ediOtros = new EditText(this);
        ArrayList<CheckBox> cb = new ArrayList<CheckBox>();

        for (int i = 0; i < opciones2.size(); i++) {
            OpcionForm opcion = opciones2.get(i);
            cb.add(new CheckBox(this));
            pregunta.addView(cb.get(i));
            cb.get(i).setText(opcion.getEtInicial());
            if (opcion.getEditble().equals("S")) {

                ediOtros.setEnabled(false);
                ediOtros.setId(R.id.edtTexto);
                pregunta.addView(ediOtros);
                cb.get(i).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        if (isChecked) {
                            ediOtros.setEnabled(true);
                        } else {
                            ediOtros.setText("");
                            ediOtros.setEnabled(false);
                        }
                    }
                });
            }

        }
        TextView spacio = new TextView(this);
        spacio.setText("        ");
        spacio.setVisibility(View.INVISIBLE);
        pregunta.addView(spacio);
        break;
    case 5:
        id = R.layout.pregunta_escala;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloEscala);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_escala);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());

        TextView etInicial = (TextView) pregunta.findViewById(R.id.etInicial);
        TextView etFinal = (TextView) pregunta.findViewById(R.id.etFinal);
        OpcionForm opci = preg.getOpciones().get(0);
        etInicial.setText(opci.getEtInicial());
        etFinal.setText(opci.getEtFinal());
        final TextView respEscala = (TextView) pregunta.findViewById(R.id.seleEscala);
        RatingBar rtBar = (RatingBar) pregunta.findViewById(R.id.escala);
        rtBar.setNumStars(Integer.parseInt(opci.getValores().get(0).getDescripcion()));
        rtBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
            @Override
            public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
                respEscala.setText("" + Math.round(rating));
            }
        });

        break;
    case 6:
        id = R.layout.pregunta_lista;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloLista);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_lista);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        ArrayList<OpcionForm> opciones3 = preg.getOpciones();
        //Creamos la lista
        LinkedList<ObjetoSpinner> opcn = new LinkedList<ObjetoSpinner>();
        //La poblamos con los ejemplos
        for (int i = 0; i < opciones3.size(); i++) {
            opcn.add(new ObjetoSpinner(opciones3.get(i).getIdOpcion(), opciones3.get(i).getEtInicial()));
        }

        //Creamos el adaptador*/
        Spinner listad = (Spinner) pregunta.findViewById(R.id.opcionesListado);
        ArrayAdapter<ObjetoSpinner> spinner_adapter = new ArrayAdapter<ObjetoSpinner>(this,
                android.R.layout.simple_spinner_item, opcn);
        //Aadimos el layout para el men y se lo damos al spinner
        spinner_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        listad.setAdapter(spinner_adapter);

        break;
    case 7:
        id = R.layout.pregunta_tabla;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloTabla);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_tabla);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        TableLayout tba = (TableLayout) pregunta.findViewById(R.id.tablaOpciones);
        ArrayList<OpcionForm> opciones4 = preg.getOpciones();
        ArrayList<RadioButton> radiosbotonoes = new ArrayList<RadioButton>();
        for (int i = 0; i < opciones4.size(); i++) {
            TableRow row = (TableRow) LayoutInflater.from(this).inflate(R.layout.row_pregunta_tabla, null);
            RadioGroup tg_valores = (RadioGroup) row.findViewById(R.id.valoresRow);

            final ArrayList<RadioButton> valoOpc = new ArrayList<RadioButton>();
            ArrayList<Valor> valoresT = opciones4.get(i).getValores();
            for (int k = 0; k < valoresT.size(); k++) {
                RadioButton rb_nuevo = new RadioButton(this);
                rb_nuevo.setText(valoresT.get(k).getDescripcion());
                tg_valores.addView(rb_nuevo);
                valoOpc.add(rb_nuevo);
            }

            ((TextView) row.findViewById(R.id.textoRow)).setText(opciones4.get(i).getEtInicial());
            tba.addView(row);
        }
        TextView espacio = new TextView(this);
        espacio.setText("        ");
        pregunta.addView(espacio);
        break;
    case 8:
        id = R.layout.pregunta_fecha;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloFecha);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_fecha);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());

        break;
    case 9:
        id = R.layout.pregunta_hora;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloHora);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_hora);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());

        break;
    default:
        id = R.layout.pregunta_multiple;
        pregunta = (LinearLayout) infla.inflate(id, null, false);

        textView = (TextView) pregunta.findViewById(R.id.TituloMultiple);
        textAyuda = (TextView) pregunta.findViewById(R.id.texto_ayuda_mltiple);
        textView.setText(preg.getOrden() + ". " + preg.getTitulo());
        textAyuda.setText(preg.getTxtAyuda());
        break;
    }

    return pregunta;
}

From source file:fr.univsavoie.ltp.client.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Appliquer le thme LTP a l'ActionBar
    //setTheme(R.style.Theme_ltp);

    // Cration de l'activit principale
    setContentView(R.layout.activity_main);

    // Instancier les classes utiles
    setPopup(new Popup(this));
    setSession(new Session(this));
    setTools(new Tools(this));

    // Afficher la ActionBar
    ActionBar mActionBar = getSupportActionBar();
    mActionBar.setHomeButtonEnabled(true);
    mActionBar.setDisplayShowHomeEnabled(true);

    // MapView settings
    map = (MapView) findViewById(R.id.openmapview);
    map.setTileSource(TileSourceFactory.MAPNIK);
    map.setBuiltInZoomControls(false);/*from  ww  w .  ja v  a  2s.co  m*/
    map.setMultiTouchControls(true);

    // MapController settings
    mapController = map.getController();

    //To use MapEventsReceiver methods, we add a MapEventsOverlay:
    overlay = new MapEventsOverlay(this, this);
    map.getOverlays().add(overlay);

    boolean isWifiEnabled = false;
    boolean isGPSEnabled = false;

    // Vrifier si le wifi ou le rseau mobile est activ
    final ConnectivityManager connMgr = (ConnectivityManager) this
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    final NetworkInfo mobile = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (wifi.isAvailable() && (wifi.getDetailedState() == DetailedState.CONNECTING
            || wifi.getDetailedState() == DetailedState.CONNECTED)) {
        Toast.makeText(this, R.string.toast_wifi, Toast.LENGTH_LONG).show();
        isWifiEnabled = true;
    } else if (mobile.isAvailable() && (mobile.getDetailedState() == DetailedState.CONNECTING
            || mobile.getDetailedState() == DetailedState.CONNECTED)) {
        Toast.makeText(this, R.string.toast_3G, Toast.LENGTH_LONG).show();
    } else {
        Toast.makeText(this, R.string.toast_aucun_reseau, Toast.LENGTH_LONG).show();
    }

    // Obtenir le service de localisation
    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

    // Verifier si le service de localisation GPS est actif, le cas echeant, tester le rseau
    if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30 * 1000, 250.0f, this);
        location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        isGPSEnabled = true;
    } else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 30 * 1000, 250.0f, this);
        location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    }

    // Afficher une boite de dialogue et proposer d'activer un ou plusieurs services pas actifs
    if (!isWifiEnabled || !isGPSEnabled) {
        //getTools().showSettingsAlert(this, isWifiEnabled, isGPSEnabled);
    }

    // Si on a une localisation, on dfinit ses coordonnes geopoint
    if (location != null) {
        startPoint = new GeoPoint(location.getLatitude(), location.getLongitude());
    } else {
        // Sinon, on indique des paramtres par dfaut
        location = getTools().getLastKnownLocation(locationManager);
        if (location == null) {
            location = new Location("");
            location.setLatitude(46.227638);
            location.setLongitude(2.213749000000);
        }
        startPoint = new GeoPoint(46.227638, 2.213749000000);
    }

    setLongitude(location.getLongitude());
    setLatitude(location.getLatitude());

    destinationPoint = null;
    viaPoints = new ArrayList<GeoPoint>();

    // On recupre quelques paramtres de la session prcdents si possible
    if (savedInstanceState == null) {
        mapController.setZoom(15);
        mapController.setCenter(startPoint);
    } else {
        mapController.setZoom(savedInstanceState.getInt("zoom_level"));
        mapController.setCenter((GeoPoint) savedInstanceState.getParcelable("map_center"));
    }

    // Crer un overlay sur la carte pour afficher notre point de dpart
    myLocationOverlay = new SimpleLocationOverlay(this, new DefaultResourceProxyImpl(this));
    map.getOverlays().add(myLocationOverlay);
    myLocationOverlay.setLocation(startPoint);

    // Boutton pour zoomer la carte
    ImageButton btZoomIn = (ImageButton) findViewById(R.id.btZoomIn);
    btZoomIn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            map.getController().zoomIn();
        }
    });

    // Boutton pour dezoomer la carte
    ImageButton btZoomOut = (ImageButton) findViewById(R.id.btZoomOut);
    btZoomOut.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            map.getController().zoomOut();
        }
    });

    // Pointeurs d'itinrairea:
    final ArrayList<ExtendedOverlayItem> waypointsItems = new ArrayList<ExtendedOverlayItem>();
    itineraryMarkers = new ItemizedOverlayWithBubble<ExtendedOverlayItem>(this, waypointsItems, map,
            new ViaPointInfoWindow(R.layout.itinerary_bubble, map));
    map.getOverlays().add(itineraryMarkers);
    //updateUIWithItineraryMarkers();

    Button searchButton = (Button) findViewById(R.id.buttonSearch);
    searchButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            handleSearchLocationButton();
        }
    });

    //context menu for clicking on the map is registered on this button. 
    registerForContextMenu(searchButton);

    // Routes et Itinraires
    final ArrayList<ExtendedOverlayItem> roadItems = new ArrayList<ExtendedOverlayItem>();
    roadNodeMarkers = new ItemizedOverlayWithBubble<ExtendedOverlayItem>(this, roadItems, map);
    map.getOverlays().add(roadNodeMarkers);

    if (savedInstanceState != null) {
        mRoad = savedInstanceState.getParcelable("road");
        updateUIWithRoad(mRoad);
    }

    //POIs:
    //POI search interface:
    String[] poiTags = getResources().getStringArray(R.array.poi_tags);
    poiTagText = (AutoCompleteTextView) findViewById(R.id.poiTag);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line,
            poiTags);
    poiTagText.setAdapter(adapter);
    Button setPOITagButton = (Button) findViewById(R.id.buttonSetPOITag);
    setPOITagButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            //Hide the soft keyboard:
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(poiTagText.getWindowToken(), 0);
            //Start search:
            getPOIAsync(poiTagText.getText().toString());
        }
    });

    //POI markers:
    final ArrayList<ExtendedOverlayItem> poiItems = new ArrayList<ExtendedOverlayItem>();
    poiMarkers = new ItemizedOverlayWithBubble<ExtendedOverlayItem>(this, poiItems, map,
            new POIInfoWindow(map));
    map.getOverlays().add(poiMarkers);
    if (savedInstanceState != null) {
        mPOIs = savedInstanceState.getParcelableArrayList("poi");
        updateUIWithPOI(mPOIs);
    }

    // Load friends ListView
    lvListeFriends = (ListView) findViewById(R.id.listViewFriends);
    //lvListeFriends.setBackgroundResource(R.drawable.listview_roundcorner_item);
    lvListeFriends.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {
            Friends item = (Friends) adapter.getItemAtPosition(position);
            if (item.getLongitude() != 0.0 && item.getLatitude() != 0.0) {
                destinationPoint = new GeoPoint(item.getLongitude(), item.getLatitude());
                markerDestination = putMarkerItem(markerDestination, destinationPoint, DEST_INDEX,
                        R.string.destination, R.drawable.marker_destination, -1);
                getRoadAsync();
                map.getController().setCenter(destinationPoint);
            } else {
                Toast.makeText(MainActivity.this, R.string.toast_friend_statut, Toast.LENGTH_LONG).show();
            }
        }
    });

    viewMapFilters = (ScrollView) this.findViewById(R.id.scrollViewMapFilters);
    viewMapFilters.setVisibility(View.GONE);

    // Initialiser tout ce qui est donnes utilisateur propres  l'activit
    init();

    getTools().relocateUser(mapController, map, myLocationOverlay, location);
}