Example usage for android.widget ArrayAdapter setDropDownViewResource

List of usage examples for android.widget ArrayAdapter setDropDownViewResource

Introduction

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

Prototype

public void setDropDownViewResource(@LayoutRes int resource) 

Source Link

Document

Sets the layout resource to create the drop down views.

Usage

From source file:com.df.dfcarchecker.CarCheck.CarCheckBasicInfoFragment.java

private void setSeriesSpinner(final Manufacturer manufacturer) {
    ArrayAdapter<String> adapter;

    if (manufacturer == null) {
        adapter = new ArrayAdapter<String>(rootView.getContext(), android.R.layout.simple_spinner_item,
                Helper.getEmptyStringList());
    } else {//from   w w w.j a va 2 s.c om
        adapter = new ArrayAdapter<String>(rootView.getContext(), android.R.layout.simple_spinner_item,
                manufacturer.getSerialNames());
    }

    seriesSpinner.setAdapter(adapter);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    // ?Spinner Adapter
    seriesSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            if (manufacturer == null || i == 0) {
                setModelSpinner(null);
            } else if (i >= 1) {
                setModelSpinner(manufacturer.serieses.get(i - 1));
            }

        }

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

        }
    });

    // ???
    if (manufacturer != null && manufacturer.getSerialNames().size() == 2) {
        seriesSpinner.setSelection(1);
    } else {
        seriesSpinner.setSelection(lastSeriesIndex);
    }

    lastSeriesIndex = 0;
}

From source file:foam.mongoose.StarwispBuilder.java

public void Build(final StarwispActivity ctx, final String ctxname, JSONArray arr, ViewGroup parent) {

    try {/*  ww w. j a va  2 s  .  c o  m*/
        String type = arr.getString(0);

        //Log.i("starwisp","building started "+type);

        if (type.equals("build-fragment")) {
            String name = arr.getString(1);
            int ID = arr.getInt(2);
            Fragment fragment = ActivityManager.GetFragment(name);
            LinearLayout inner = new LinearLayout(ctx);
            inner.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            inner.setId(ID);
            FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction();
            fragmentTransaction.add(ID, fragment);
            fragmentTransaction.commit();
            parent.addView(inner);
            return;
        }

        if (type.equals("linear-layout")) {
            LinearLayout v = new LinearLayout(ctx);
            v.setId(arr.getInt(1));
            v.setOrientation(BuildOrientation(arr.getString(2)));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            //v.setPadding(2,2,2,2);
            JSONArray col = arr.getJSONArray(4);
            v.setBackgroundColor(Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(5);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        if (type.equals("frame-layout")) {
            FrameLayout v = new FrameLayout(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        /*
        if (type.equals("grid-layout")) {
        GridLayout v = new GridLayout(ctx);
        v.setId(arr.getInt(1));
        v.setRowCount(arr.getInt(2));
        //v.setColumnCount(arr.getInt(2));
        v.setOrientation(BuildOrientation(arr.getString(3)));
        v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
                
        parent.addView(v);
        JSONArray children = arr.getJSONArray(5);
        for (int i=0; i<children.length(); i++) {
            Build(ctx,ctxname,new JSONArray(children.getString(i)), v);
        }
                
        return;
        }
        */

        if (type.equals("scroll-view")) {
            HorizontalScrollView v = new HorizontalScrollView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        if (type.equals("scroll-view-vert")) {
            ScrollView v = new ScrollView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        if (type.equals("view-pager")) {
            ViewPager v = new ViewPager(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            v.setOffscreenPageLimit(3);
            final JSONArray items = arr.getJSONArray(3);

            v.setAdapter(new FragmentPagerAdapter(ctx.getSupportFragmentManager()) {

                @Override
                public int getCount() {
                    return items.length();
                }

                @Override
                public Fragment getItem(int position) {
                    try {
                        String fragname = items.getString(position);
                        return ActivityManager.GetFragment(fragname);
                    } catch (JSONException e) {
                        Log.e("starwisp", "Error parsing data " + e.toString());
                    }
                    return null;
                }
            });
            parent.addView(v);
            return;
        }

        if (type.equals("space")) {
            // Space v = new Space(ctx); (class not found runtime error??)
            TextView v = new TextView(ctx);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
        }

        if (type.equals("image-view")) {
            ImageView v = new ImageView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));

            String image = arr.getString(2);

            if (image.startsWith("/")) {
                Bitmap bitmap = BitmapFactory.decodeFile(image);
                v.setImageBitmap(bitmap);
            } else {
                int id = ctx.getResources().getIdentifier(image, "drawable", ctx.getPackageName());
                v.setImageResource(id);
            }

            parent.addView(v);
        }

        if (type.equals("text-view")) {
            TextView v = new TextView(ctx);
            v.setId(arr.getInt(1));
            v.setText(Html.fromHtml(arr.getString(2)));
            v.setTextSize(arr.getInt(3));
            v.setMovementMethod(LinkMovementMethod.getInstance());
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            if (arr.length() > 5) {
                if (arr.getString(5).equals("left")) {
                    v.setGravity(Gravity.LEFT);
                } else {
                    if (arr.getString(5).equals("fill")) {
                        v.setGravity(Gravity.FILL);
                    } else {
                        v.setGravity(Gravity.CENTER);
                    }
                }
            } else {
                v.setGravity(Gravity.LEFT);
            }
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            parent.addView(v);
        }

        if (type.equals("debug-text-view")) {
            TextView v = (TextView) ctx.getLayoutInflater().inflate(R.layout.debug_text, null);
            //                v.setBackgroundResource(R.color.black);
            v.setId(arr.getInt(1));
            //                v.setText(Html.fromHtml(arr.getString(2)));
            //                v.setTextColor(R.color.white);
            //                v.setTextSize(arr.getInt(3));
            //                v.setMovementMethod(LinkMovementMethod.getInstance());
            //                v.setMaxLines(10);
            //                v.setVerticalScrollBarEnabled(true);
            //                v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            //v.setMovementMethod(new ScrollingMovementMethod());

            /*
            if (arr.length()>5) {
            if (arr.getString(5).equals("left")) {
                v.setGravity(Gravity.LEFT);
            } else {
                if (arr.getString(5).equals("fill")) {
                    v.setGravity(Gravity.FILL);
                } else {
                    v.setGravity(Gravity.CENTER);
                }
            }
            } else {
            v.setGravity(Gravity.LEFT);
            }
            v.setTypeface(((StarwispActivity)ctx).m_Typeface);*/
            parent.addView(v);
        }

        if (type.equals("web-view")) {
            WebView v = new WebView(ctx);
            v.setId(arr.getInt(1));
            v.setVerticalScrollBarEnabled(false);
            v.loadData(arr.getString(2), "text/html", "utf-8");
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            parent.addView(v);
        }

        if (type.equals("edit-text")) {
            final EditText v = new EditText(ctx);
            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));

            String inputtype = arr.getString(4);
            if (inputtype.equals("text")) {
                //v.setInputType(InputType.TYPE_CLASS_TEXT);
            } else if (inputtype.equals("numeric")) {
                v.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
            } else if (inputtype.equals("email")) {
                v.setInputType(InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS);
            }

            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(5)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(5);
            v.setSingleLine(true);

            v.addTextChangedListener(new TextWatcher() {
                public void afterTextChanged(Editable s) {
                    CallbackArgs(ctx, ctxname, v.getId(), "\"" + s.toString() + "\"");
                }

                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                }

                public void onTextChanged(CharSequence s, int start, int before, int count) {
                }
            });

            parent.addView(v);
        }

        if (type.equals("button")) {
            Button v = new Button(ctx);
            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(5);
            v.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Callback(ctx, ctxname, v.getId());
                }
            });
            parent.addView(v);
        }

        if (type.equals("toggle-button")) {
            ToggleButton v = new ToggleButton(ctx);
            if (arr.getString(5).equals("fancy")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_fancy, null);
            }

            if (arr.getString(5).equals("yes")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_yes, null);
            }

            if (arr.getString(5).equals("maybe")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_maybe, null);
            }

            if (arr.getString(5).equals("no")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_no, null);
            }

            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(6);
            v.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    String arg = "#f";
                    if (((ToggleButton) v).isChecked())
                        arg = "#t";
                    CallbackArgs(ctx, ctxname, v.getId(), arg);
                }
            });
            parent.addView(v);
        }

        if (type.equals("seek-bar")) {
            SeekBar v = new SeekBar(ctx);
            v.setId(arr.getInt(1));
            v.setMax(arr.getInt(2));
            v.setProgress(arr.getInt(2) / 2);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            final String fn = arr.getString(4);

            v.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                public void onProgressChanged(SeekBar v, int a, boolean s) {
                    CallbackArgs(ctx, ctxname, v.getId(), Integer.toString(a));
                }

                public void onStartTrackingTouch(SeekBar v) {
                }

                public void onStopTrackingTouch(SeekBar v) {
                }
            });
            parent.addView(v);
        }

        if (type.equals("spinner")) {
            Spinner v = new Spinner(ctx);
            final int wid = arr.getInt(1);
            v.setId(wid);
            final JSONArray items = arr.getJSONArray(2);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            ArrayList<String> spinnerArray = new ArrayList<String>();

            for (int i = 0; i < items.length(); i++) {
                spinnerArray.add(items.getString(i));
            }

            ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<String>(ctx, R.layout.spinner_item,
                    spinnerArray) {
                public View getView(int position, View convertView, ViewGroup parent) {
                    View v = super.getView(position, convertView, parent);
                    ((TextView) v).setTypeface(((StarwispActivity) ctx).m_Typeface);
                    return v;
                }
            };

            spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_layout);

            v.setAdapter(spinnerArrayAdapter);
            v.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> a, View v, int pos, long id) {
                    try {
                        CallbackArgs(ctx, ctxname, wid, "\"" + items.getString(pos) + "\"");
                    } catch (JSONException e) {
                        Log.e("starwisp", "Error parsing data " + e.toString());
                    }
                }

                public void onNothingSelected(AdapterView<?> v) {
                }
            });

            parent.addView(v);
        }

        if (type.equals("canvas")) {
            StarwispCanvas v = new StarwispCanvas(ctx);
            final int wid = arr.getInt(1);
            v.setId(wid);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            v.SetDrawList(arr.getJSONArray(3));
            parent.addView(v);
        }

        if (type.equals("camera-preview")) {
            PictureTaker pt = new PictureTaker();
            CameraPreview v = new CameraPreview(ctx, pt);
            final int wid = arr.getInt(1);
            v.setId(wid);

            //              LinearLayout.LayoutParams lp =
            //  new LinearLayout.LayoutParams(minWidth, minHeight, 1);

            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));

            //                v.setLayoutParams(lp);
            parent.addView(v);
        }

        if (type.equals("button-grid")) {
            LinearLayout horiz = new LinearLayout(ctx);
            final int id = arr.getInt(1);
            final String buttontype = arr.getString(2);
            horiz.setId(id);
            horiz.setOrientation(LinearLayout.HORIZONTAL);
            parent.addView(horiz);
            int height = arr.getInt(3);
            int textsize = arr.getInt(4);
            LinearLayout.LayoutParams lp = BuildLayoutParams(arr.getJSONArray(5));
            JSONArray buttons = arr.getJSONArray(6);
            int count = buttons.length();
            int vertcount = 0;
            LinearLayout vert = null;

            for (int i = 0; i < count; i++) {
                JSONArray button = buttons.getJSONArray(i);

                if (vertcount == 0) {
                    vert = new LinearLayout(ctx);
                    vert.setId(0);
                    vert.setOrientation(LinearLayout.VERTICAL);
                    horiz.addView(vert);
                }
                vertcount = (vertcount + 1) % height;

                if (buttontype.equals("button")) {
                    Button b = new Button(ctx);
                    b.setId(button.getInt(0));
                    b.setText(button.getString(1));
                    b.setTextSize(textsize);
                    b.setLayoutParams(lp);
                    b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                    final String fn = arr.getString(6);
                    b.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t");
                        }
                    });
                    vert.addView(b);
                } else if (buttontype.equals("toggle")) {
                    ToggleButton b = new ToggleButton(ctx);
                    b.setId(button.getInt(0));
                    b.setText(button.getString(1));
                    b.setTextSize(textsize);
                    b.setLayoutParams(lp);
                    b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                    final String fn = arr.getString(6);
                    b.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            String arg = "#f";
                            if (((ToggleButton) v).isChecked())
                                arg = "#t";
                            CallbackArgs(ctx, ctxname, id, "" + v.getId() + " " + arg);
                        }
                    });
                    vert.addView(b);
                }
            }
        }

    } catch (JSONException e) {
        Log.e("starwisp", "Error parsing [" + arr.toString() + "] " + e.toString());
    }

    //Log.i("starwisp","building ended");

}

From source file:com.mantz_it.rfanalyzer.MainActivity.java

public void showRecordingDialog() {
    if (!running || scheduler == null || demodulator == null || source == null) {
        Toast.makeText(MainActivity.this, "Analyzer must be running to start recording", Toast.LENGTH_LONG)
                .show();/*from w  w w  . j a  va  2  s . c o  m*/
        return;
    }

    // Check for the WRITE_EXTERNAL_STORAGE permission:
    if (ContextCompat.checkSelfPermission(this,
            "android.permission.WRITE_EXTERNAL_STORAGE") != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[] { "android.permission.WRITE_EXTERNAL_STORAGE" },
                PERMISSION_REQUEST_RECORDING_WRITE_FILES);
        return; // wait for the permission response (handled in onRequestPermissionResult())
    }

    final String externalDir = Environment.getExternalStorageDirectory().getAbsolutePath();
    final int[] supportedSampleRates = source.getSupportedSampleRates();
    final double maxFreqMHz = source.getMaxFrequency() / 1000000f; // max frequency of the source in MHz
    final int sourceType = Integer.valueOf(preferences.getString(getString(R.string.pref_sourceType), "1"));
    final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.US);

    // Get references to the GUI components:
    final ScrollView view = (ScrollView) this.getLayoutInflater().inflate(R.layout.start_recording, null);
    final EditText et_filename = (EditText) view.findViewById(R.id.et_recording_filename);
    final EditText et_frequency = (EditText) view.findViewById(R.id.et_recording_frequency);
    final Spinner sp_sampleRate = (Spinner) view.findViewById(R.id.sp_recording_sampleRate);
    final TextView tv_fixedSampleRateHint = (TextView) view.findViewById(R.id.tv_recording_fixedSampleRateHint);
    final CheckBox cb_stopAfter = (CheckBox) view.findViewById(R.id.cb_recording_stopAfter);
    final EditText et_stopAfter = (EditText) view.findViewById(R.id.et_recording_stopAfter);
    final Spinner sp_stopAfter = (Spinner) view.findViewById(R.id.sp_recording_stopAfter);

    // Setup the sample rate spinner:
    final ArrayAdapter<Integer> sampleRateAdapter = new ArrayAdapter<Integer>(this,
            android.R.layout.simple_list_item_1);
    for (int sampR : supportedSampleRates)
        sampleRateAdapter.add(sampR);
    sampleRateAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sp_sampleRate.setAdapter(sampleRateAdapter);

    // Add listener to the frequency textfield, the sample rate spinner and the checkbox:
    et_frequency.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (et_frequency.getText().length() == 0)
                return;
            double freq = Double.valueOf(et_frequency.getText().toString());
            if (freq < maxFreqMHz)
                freq = freq * 1000000;
            et_filename.setText(simpleDateFormat.format(new Date()) + "_" + SOURCE_NAMES[sourceType] + "_"
                    + (long) freq + "Hz_" + sp_sampleRate.getSelectedItem() + "Sps.iq");
        }
    });
    sp_sampleRate.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (et_frequency.getText().length() == 0)
                return;
            double freq = Double.valueOf(et_frequency.getText().toString());
            if (freq < maxFreqMHz)
                freq = freq * 1000000;
            et_filename.setText(simpleDateFormat.format(new Date()) + "_" + SOURCE_NAMES[sourceType] + "_"
                    + (long) freq + "Hz_" + sp_sampleRate.getSelectedItem() + "Sps.iq");
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    cb_stopAfter.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            et_stopAfter.setEnabled(isChecked);
            sp_stopAfter.setEnabled(isChecked);
        }
    });

    // Set default frequency, sample rate and stop after values:
    et_frequency.setText("" + analyzerSurface.getVirtualFrequency());
    int sampleRateIndex = 0;
    int lastSampleRate = preferences.getInt(getString(R.string.pref_recordingSampleRate), 1000000);
    for (; sampleRateIndex < supportedSampleRates.length; sampleRateIndex++) {
        if (supportedSampleRates[sampleRateIndex] >= lastSampleRate)
            break;
    }
    if (sampleRateIndex >= supportedSampleRates.length)
        sampleRateIndex = supportedSampleRates.length - 1;
    sp_sampleRate.setSelection(sampleRateIndex);
    cb_stopAfter.toggle(); // just to trigger the listener at least once!
    cb_stopAfter.setChecked(preferences.getBoolean(getString(R.string.pref_recordingStopAfterEnabled), false));
    et_stopAfter.setText("" + preferences.getInt(getString(R.string.pref_recordingStopAfterValue), 10));
    sp_stopAfter.setSelection(preferences.getInt(getString(R.string.pref_recordingStopAfterUnit), 0));

    // disable sample rate selection if demodulation is running:
    if (demodulationMode != Demodulator.DEMODULATION_OFF) {
        sampleRateAdapter.add(source.getSampleRate()); // add the current sample rate in case it's not already in the list
        sp_sampleRate.setSelection(sampleRateAdapter.getPosition(source.getSampleRate())); // select it
        sp_sampleRate.setEnabled(false); // disable the spinner
        tv_fixedSampleRateHint.setVisibility(View.VISIBLE);
    }

    // Show dialog:
    new AlertDialog.Builder(this).setTitle("Start recording").setView(view)
            .setPositiveButton("Record", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    String filename = et_filename.getText().toString();
                    final int stopAfterUnit = sp_stopAfter.getSelectedItemPosition();
                    final int stopAfterValue = Integer.valueOf(et_stopAfter.getText().toString());
                    //todo check filename

                    // Set the frequency in the source:
                    if (et_frequency.getText().length() == 0)
                        return;
                    double freq = Double.valueOf(et_frequency.getText().toString());
                    if (freq < maxFreqMHz)
                        freq = freq * 1000000;
                    if (freq <= source.getMaxFrequency() && freq >= source.getMinFrequency())
                        source.setFrequency((long) freq);
                    else {
                        Toast.makeText(MainActivity.this, "Frequency is invalid!", Toast.LENGTH_LONG).show();
                        return;
                    }

                    // Set the sample rate (only if demodulator is off):
                    if (demodulationMode == Demodulator.DEMODULATION_OFF)
                        source.setSampleRate((Integer) sp_sampleRate.getSelectedItem());

                    // Open file and start recording:
                    recordingFile = new File(externalDir + "/" + RECORDING_DIR + "/" + filename);
                    recordingFile.getParentFile().mkdir(); // Create directory if it does not yet exist
                    try {
                        scheduler.startRecording(new BufferedOutputStream(new FileOutputStream(recordingFile)));
                    } catch (FileNotFoundException e) {
                        Log.e(LOGTAG,
                                "showRecordingDialog: File not found: " + recordingFile.getAbsolutePath());
                    }

                    // safe preferences:
                    SharedPreferences.Editor edit = preferences.edit();
                    edit.putInt(getString(R.string.pref_recordingSampleRate),
                            (Integer) sp_sampleRate.getSelectedItem());
                    edit.putBoolean(getString(R.string.pref_recordingStopAfterEnabled),
                            cb_stopAfter.isChecked());
                    edit.putInt(getString(R.string.pref_recordingStopAfterValue), stopAfterValue);
                    edit.putInt(getString(R.string.pref_recordingStopAfterUnit), stopAfterUnit);
                    edit.apply();

                    analyzerSurface.setRecordingEnabled(true);

                    updateActionBar();

                    // if stopAfter was selected, start thread to supervise the recording:
                    if (cb_stopAfter.isChecked()) {
                        Thread supervisorThread = new Thread() {
                            @Override
                            public void run() {
                                Log.i(LOGTAG, "recording_superviser: Supervisor Thread started. (Thread: "
                                        + this.getName() + ")");
                                try {
                                    long startTime = System.currentTimeMillis();
                                    boolean stop = false;

                                    // We check once per half a second if the stop criteria is met:
                                    Thread.sleep(500);
                                    while (recordingFile != null && !stop) {
                                        switch (stopAfterUnit) { // see arrays.xml - recording_stopAfterUnit
                                        case 0: /* MB */
                                            if (recordingFile.length() / 1000000 >= stopAfterValue)
                                                stop = true;
                                            break;
                                        case 1: /* GB */
                                            if (recordingFile.length() / 1000000000 >= stopAfterValue)
                                                stop = true;
                                            break;
                                        case 2: /* sec */
                                            if (System.currentTimeMillis() - startTime >= stopAfterValue * 1000)
                                                stop = true;
                                            break;
                                        case 3: /* min */
                                            if (System.currentTimeMillis() - startTime >= stopAfterValue * 1000
                                                    * 60)
                                                stop = true;
                                            break;
                                        }
                                    }
                                    // stop recording:
                                    stopRecording();
                                } catch (InterruptedException e) {
                                    Log.e(LOGTAG, "recording_superviser: Interrupted!");
                                } catch (NullPointerException e) {
                                    Log.e(LOGTAG, "recording_superviser: Recording file is null!");
                                }
                                Log.i(LOGTAG, "recording_superviser: Supervisor Thread stopped. (Thread: "
                                        + this.getName() + ")");
                            }
                        };
                        supervisorThread.start();
                    }
                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // do nothing
                }
            }).show().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}

From source file:gr.scify.newsum.ui.ViewActivity.java

@Override
public void run() {
    // take the String from the TopicActivity
    Bundle extras = getIntent().getExtras();
    Category = extras.getString(CATEGORY_INTENT_VAR);

    // Make sure we have updated the data source
    NewSumUiActivity.setDataSource(this);

    // Get user sources
    String sUserSources = Urls.getUserVisibleURLsAsString(ViewActivity.this);

    // get Topics from TopicActivity (avoid multiple server calls)
    TopicInfo[] tiTopics = TopicActivity.getTopics(sUserSources, Category, this);

    // Also get Topic Titles, to display to adapter
    final String[] saTopicTitles = new String[tiTopics.length];
    // Also get Topic IDs
    final String[] saTopicIDs = new String[tiTopics.length];
    // Also get Dates, in order to show in summary title
    final String[] saTopicDates = new String[tiTopics.length];
    // DeHTML titles
    for (int iCnt = 0; iCnt < tiTopics.length; iCnt++) {
        // update Titles Array
        saTopicTitles[iCnt] = Html.fromHtml(tiTopics[iCnt].getTitle()).toString();
        // update IDs Array
        saTopicIDs[iCnt] = tiTopics[iCnt].getID();
        // update Date Array
        saTopicDates[iCnt] = tiTopics[iCnt].getPrintableDate(NewSumUiActivity.getDefaultLocale());
    }//from  w  w w  .ja  v  a  2s  .  c  o  m
    // get the value of the TopicIDs list size (to use in swipe)
    saTopicIDsLength = saTopicIDs.length;
    final TextView title = (TextView) findViewById(R.id.title);
    // Fill topic spinner
    final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this,
            android.R.layout.simple_spinner_item, saTopicTitles);

    final TextView tx = (TextView) findViewById(R.id.textView1);
    //      final float minm = tx.getTextSize();
    //      final float maxm = (minm + 24);

    // Get active topic
    int iTopicNum;
    // If we have returned from a pause
    if (iPrvSelectedItem >= 0)
        // use previous selection before pause
        iTopicNum = iPrvSelectedItem;
    // else
    else
        // use selection from topic page
        iTopicNum = extras.getInt(TOPIC_ID_INTENT_VAR);
    final int num = iTopicNum;

    // create an invisible spinner just to control the summaries of the
    // category (i will use it later on Swipe)
    final Spinner spinner = (Spinner) findViewById(R.id.spinner1);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            spinner.setAdapter(adapter);

            // Scroll view init
            final ScrollView scroll = (ScrollView) findViewById(R.id.scrollView1);
            final String[] saTopicTitlesArg = saTopicTitles;
            final String[] saTopicIDsArg = saTopicIDs;
            final String[] SaTopicDatesArg = saTopicDates;

            // Add selection event
            spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                    // Changing summary
                    loading = true;
                    showWaitingDialog();
                    // Update visibility of rating bar
                    final RatingBar rb = (RatingBar) findViewById(R.id.ratingBar);
                    rb.setRating(0.0f);
                    rb.setVisibility(View.VISIBLE);
                    final TextView rateLbl = (TextView) findViewById(R.id.rateLbl);
                    rateLbl.setVisibility(View.VISIBLE);
                    scroll.scrollTo(0, 0);

                    String UserSources = Urls.getUserVisibleURLsAsString(ViewActivity.this);

                    String[] saTopicIDs = saTopicIDsArg;

                    // track summary views per category and topic title
                    if (getAnalyticsPref()) {
                        EasyTracker.getTracker().sendEvent(VIEW_SUMMARY_ACTION, Category,
                                saTopicTitlesArg[arg2], 0l);
                    }

                    if (sCustomCategory.trim().length() > 0) {
                        if (Category.equals(sCustomCategory)) {
                            Context ctxCur = NewSumUiActivity.getAppContext(ViewActivity.this);
                            String sCustomCategoryURL = ctxCur.getResources()
                                    .getString(R.string.custom_category_url);
                            // Check if specific element needs to be read
                            String sElementID = ctxCur.getResources()
                                    .getString(R.string.custom_category_elementId);
                            // If an element needs to be selected
                            if (sElementID.trim().length() > 0) {
                                try {
                                    // Check if specific element needs to be read
                                    String sViewOriginalPage = ctxCur.getResources()
                                            .getString(R.string.custom_category_visit_source);
                                    // Init text by a link to the original page
                                    sText = "<p><a href='" + sCustomCategoryURL + "'>" + sViewOriginalPage
                                            + "</a></p>";
                                    // Get document
                                    Document doc = Jsoup.connect(sCustomCategoryURL).get();
                                    // If a table
                                    Element eCur = doc.getElementById(sElementID);
                                    if (eCur.tagName().equalsIgnoreCase("table")) {
                                        // Get table rows
                                        Elements eRows = eCur.select("tr");

                                        // For each row
                                        StringBuffer sTextBuf = new StringBuffer();
                                        for (Element eCurRow : eRows) {
                                            // Append content
                                            // TODO: Use HTML if possible. Now problematic (crashes when we click on link)
                                            sTextBuf.append("<p>" + eCurRow.text() + "</p>");
                                        }
                                        // Return as string
                                        sText = sText + sTextBuf.toString();
                                    } else
                                        // else get text
                                        sText = eCur.text();

                                } catch (IOException e) {
                                    // Show unavailable text
                                    sText = ctxCur.getResources()
                                            .getString(R.string.custom_category_unavailable);
                                    e.printStackTrace();
                                }

                            } else
                                sText = Utils.getFromHttp(sCustomCategoryURL, false);
                        }

                    } else {
                        // call getSummary with (sTopicID, sUserSources). Use "All" for
                        // all Sources
                        String[] Summary = NewSumServiceClient.getSummary(saTopicIDs[arg2], UserSources);
                        // check if Summary exists, otherwise display message
                        if (Summary.length == 0) { // DONE APPLICATION HANGS, DOES NOT
                            // WORK. Updated: Probably OK
                            nothingFound = true;
                            AlertDialog.Builder al = new AlertDialog.Builder(ViewActivity.this);
                            al.setMessage(R.string.shouldReloadSummaries);
                            al.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface arg0, int arg1) {
                                    // Reset cache
                                    CacheController.clearCache();
                                    // Restart main activity
                                    startActivity(new Intent(getApplicationContext(), NewSumUiActivity.class)
                                            .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
                                }
                            });
                            al.setCancelable(false);
                            al.show();
                            // Return to home activity
                            loading = false;
                            return;
                        }
                        // Generate Summary text for normal categories
                        sText = generateSummaryText(Summary, ViewActivity.this);
                        pText = generatesummarypost(Summary, ViewActivity.this);
                    }

                    // Update HTML
                    tx.setText(Html.fromHtml(sText));
                    // Allow links to be followed into browser
                    tx.setMovementMethod(LinkMovementMethod.getInstance());
                    // Also Add Date to Topic Title inside Summary
                    title.setText(saTopicTitlesArg[arg2] + " : " + SaTopicDatesArg[arg2]);

                    // Update size
                    updateTextSize();

                    // Update visited topics
                    TopicActivity.addVisitedTopicID(saTopicIDs[arg2]);
                    // Done
                    loading = false;
                    closeWaitingDialog();
                }

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

            });

            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    // Get active topic
                    spinner.setSelection(num);
                }
            });

        }
    });

    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            showHelpDialog();
        }
    });

    closeWaitingDialog();
}

From source file:com.housekeeper.ar.healthhousekeeper.personalinfo.ModifyInfoActivity.java

private void initData() {
    try {//from w  ww.  ja  v  a 2 s. com
        usernameET.setText(joDoc.getString("userId"));
        //psdET.setText(joDoc.getString(""));
        nameET.setText(joDoc.getString("name"));
        idET.setText(joDoc.getString("identity"));

        telET.setText(joDoc.getString("phone"));
        mailET.setText(joDoc.getString("email"));
        //TODO ?
        //            workIdEditText.setText(joDoc.getString("workID"));

        sexStr = joDoc.getString("sex");
        birthdayStr = joDoc.getString("birthday");
        yearStr = birthdayStr.substring(0, 4);
        monthStr = birthdayStr.substring(5, 7);
        dayStr = birthdayStr.substring(8);
        Log.i(TAG, "yearString " + yearStr + " monthString " + monthStr + " dayString " + dayStr);

    } catch (JSONException e) {
        e.printStackTrace();
    }

    final List<String> yearList = getYearData();
    final List<String> monthList = getMonthData();
    final List<String> dayList = getDayData();
    final List<String> sexList = getSexData();

    ArrayAdapter<String> yearAdapter = new ArrayAdapter<String>(ModifyInfoActivity.this, R.layout.spinner_item,
            yearList) {
        @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = (LayoutInflater) getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View view = inflater.inflate(R.layout.spinner_item_layout, null);
            TextView label = (TextView) view.findViewById(R.id.spinner_item_label);

            label.setText(yearList.get(position));

            return view;
            //return super.getDropDownView(position, convertView, parent);
        }
    };
    ArrayAdapter<String> monthAdapter = new ArrayAdapter<String>(ModifyInfoActivity.this, R.layout.spinner_item,
            getMonthData()) {
        @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = (LayoutInflater) getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View view = inflater.inflate(R.layout.spinner_item_layout, null);
            TextView label = (TextView) view.findViewById(R.id.spinner_item_label);

            label.setText(monthList.get(position));

            return view;
            //return super.getDropDownView(position, convertView, parent);
        }
    };
    ArrayAdapter<String> dayAdapter = new ArrayAdapter<String>(ModifyInfoActivity.this, R.layout.spinner_item,
            getDayData()) {
        @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = (LayoutInflater) getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View view = inflater.inflate(R.layout.spinner_item_layout, null);
            TextView label = (TextView) view.findViewById(R.id.spinner_item_label);

            label.setText(dayList.get(position));

            return view;
            //return super.getDropDownView(position, convertView, parent);
        }
    };
    year.setAdapter(yearAdapter);
    //      year.setSelection(default_year_pos, true);
    month.setAdapter(monthAdapter);
    //      month.setSelection(default_month_pos, true);
    day.setAdapter(dayAdapter);
    //      day.setSelection(default_day_pos, true);

    ArrayAdapter<String> sexAdapter = new ArrayAdapter<String>(ModifyInfoActivity.this, R.layout.spinner_item,
            getSexData()) {
        @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = (LayoutInflater) getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View view = inflater.inflate(R.layout.spinner_item_layout, null);
            TextView label = (TextView) view.findViewById(R.id.spinner_item_label);

            label.setText(sexList.get(position));

            return view;
            //return super.getDropDownView(position, convertView, parent);
        }
    };
    sex.setAdapter(sexAdapter);
    //        sex.setSelection(default_sex_pos, true);

    //      ArrayAdapter<String> proAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item,namePros){
    //         @Override
    //         public View getDropDownView(int position, View convertView, ViewGroup parent) {
    //            LayoutInflater inflater=(LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    //            View view = inflater.inflate(R.layout.spinner_item_layout,
    //                  null);
    //            TextView label = (TextView) view
    //                  .findViewById(R.id.spinner_item_label);
    //
    //            label.setText(namePros[position]);
    //
    //
    //            return view;
    //            //return super.getDropDownView(position, convertView, parent);
    //         }
    //      };
    //      //?
    //
    //      proAdapter.setDropDownViewResource(R.layout.spinner_item_layout);
    ////      proAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    //      pro.setAdapter(proAdapter);
    //      pro.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    //
    //            @Override
    //            public void onItemSelected(AdapterView<?> parent, View view,
    //                                       int position, long id) {
    //                // TODO Auto-generated method stub
    //                proStr = parent.getItemAtPosition(position).toString();
    //                Log.v(TAG, "selcet proStr:" + proStr);
    //                if (proStr.equals(namePros[position])) {
    //                    idJobTitlesInt = idJobTitles[position];
    //                }
    //            }
    //
    //            @Override
    //            public void onNothingSelected(AdapterView<?> arg0) {
    //                // TODO Auto-generated method stub
    //
    //            }
    //
    //        });
    //        try {
    //            pro.setSelection(joDoc.getInt("jobTitleId")-1,true);
    //        } catch (JSONException e) {
    //            e.printStackTrace();
    //        }

    ArrayAdapter<String> shengAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item, nameProvinces) {
        @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = (LayoutInflater) getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View view = inflater.inflate(R.layout.spinner_item_layout, null);
            TextView label = (TextView) view.findViewById(R.id.spinner_item_label);

            label.setText(nameProvinces[position]);

            return view;
            //return super.getDropDownView(position, convertView, parent);
        }
    };
    //?

    shengAdapter.setDropDownViewResource(R.layout.spinner_item_layout);
    sheng.setAdapter(shengAdapter);
    sheng.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> shengparent, View shengview, int shengposition,
                long shengid) {
            // TODO Auto-generated method stub
            myApp.setShengposition(shengposition);
            shengStr = shengparent.getItemAtPosition(shengposition).toString();
            Log.v(TAG, "shengStr:" + shengStr);
            if (shengStr.equals(nameProvinces[shengposition])) {
                Log.v(TAG, "position:" + shengposition);
                for (int i = 0; i < joProvinces.length; i++) {
                    try {

                        if (shengStr.equals(joProvinces[i].getString("name"))) {
                            jaCities = joProvinces[i].getJSONArray("cities");
                            joCities = new JSONObject[jaCities.length()];
                            nameCities = new String[joCities.length];

                            for (int j = 0; j < jaCities.length(); j++) {
                                joCities[j] = jaCities.getJSONObject(j);
                                nameCities[j] = joCities[j].getString("name");
                            }
                        }
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block

                        e.printStackTrace();
                    }
                }
            }
            sheng.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View view, MotionEvent motionEvent) {

                    Log.i(TAG, "year touch ");
                    closeSoftKeyboard();
                    return false;
                }
            });
            shiAdapter = new ArrayAdapter<String>(ModifyInfoActivity.this, R.layout.spinner_item, nameCities) {
                @Override
                public View getDropDownView(int position, View convertView, ViewGroup parent) {
                    LayoutInflater inflater = (LayoutInflater) getContext()
                            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    View view = inflater.inflate(R.layout.spinner_item_layout, null);
                    TextView label = (TextView) view.findViewById(R.id.spinner_item_label);

                    label.setText(nameCities[position]);

                    return view;
                    //return super.getDropDownView(position, convertView, parent);
                }
            };

            //?
            shiAdapter.setDropDownViewResource(R.layout.spinner_item_layout);

            //            shiAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            shi.setAdapter(shiAdapter);

            shi.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

                @Override
                public void onItemSelected(AdapterView<?> shiparent, View shiview, int shiposition,
                        long shiid) {
                    // TODO Auto-generated method stub
                    shiStr = shiparent.getItemAtPosition(shiposition).toString();
                    Log.v(TAG, "shiStr:" + shiStr);
                    if (shiStr.equals(nameCities[shiposition])) {
                        for (int i = 0; i < joCities.length; i++) {
                            try {
                                if (shiStr.equals(joCities[i].getString("name"))) {
                                    jaHospitals = joCities[i].getJSONArray("hospitals");
                                    joHospitals = new JSONObject[jaHospitals.length()];
                                    nameHospitals = new String[joHospitals.length];
                                    for (int j = 0; j < jaHospitals.length(); j++) {
                                        joHospitals[j] = jaHospitals.getJSONObject(j);
                                        nameHospitals[j] = joHospitals[j].getString("name");
                                    }

                                }
                            } catch (JSONException e) {
                                // TODO Auto-generated catch block

                                e.printStackTrace();
                            }
                        }
                    }
                    shi.setOnTouchListener(new View.OnTouchListener() {
                        @Override
                        public boolean onTouch(View view, MotionEvent motionEvent) {

                            Log.i(TAG, "year touch ");
                            closeSoftKeyboard();
                            return false;
                        }
                    });
                    hospitalAdapter = new ArrayAdapter<String>(ModifyInfoActivity.this, R.layout.spinner_item,
                            nameHospitals) {
                        @Override
                        public View getDropDownView(int position, View convertView, ViewGroup parent) {
                            LayoutInflater inflater = (LayoutInflater) getContext()
                                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                            View view = inflater.inflate(R.layout.spinner_item_layout, null);
                            TextView label = (TextView) view.findViewById(R.id.spinner_item_label);

                            label.setText(nameHospitals[position]);

                            return view;
                            //return super.getDropDownView(position, convertView, parent);
                        }
                    };

                    //?
                    hospitalAdapter.setDropDownViewResource(R.layout.spinner_item_layout);
                    yy.setAdapter(hospitalAdapter);

                    yy.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

                        @Override
                        public void onItemSelected(AdapterView<?> yyparent, View yyview, int yyposition,
                                long yyid) {
                            // TODO Auto-generated method stub
                            yyStr = yyparent.getItemAtPosition(yyposition).toString();
                            if (yyStr.equals(nameHospitals[yyposition])) {
                                for (int i = 0; i < joHospitals.length; i++) {
                                    try {
                                        if (yyStr.equals(joHospitals[i].getString("name"))) {
                                            jaDepartments = joHospitals[i].getJSONArray("departments");
                                            joDepartments = new JSONObject[jaDepartments.length()];
                                            nameDepartments = new String[joDepartments.length];
                                            idDepartments = new int[joDepartments.length];
                                            for (int j = 0; j < jaDepartments.length(); j++) {
                                                joDepartments[j] = jaDepartments.getJSONObject(j);
                                                nameDepartments[j] = joDepartments[j].getString("name");
                                                idDepartments[j] = joDepartments[j].getInt("id");

                                            }

                                        }
                                    } catch (JSONException e) {
                                        // TODO Auto-generated catch block

                                        e.printStackTrace();
                                    }
                                }
                            }
                            yy.setOnTouchListener(new View.OnTouchListener() {
                                @Override
                                public boolean onTouch(View view, MotionEvent motionEvent) {

                                    Log.i(TAG, "year touch ");
                                    closeSoftKeyboard();
                                    return false;
                                }
                            });
                            //                                departmentAdapter = new ArrayAdapter<String>(ModifyInfoActivity.this, android.R.layout.simple_spinner_item, nameDepartments) {
                            //                                    @Override
                            //                                    public View getDropDownView(int position, View convertView, ViewGroup parent) {
                            //                                        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                            //                                        View view = inflater.inflate(R.layout.spinner_item_layout,
                            //                                                null);
                            //                                        TextView label = (TextView) view
                            //                                                .findViewById(R.id.spinner_item_label);
                            //
                            //                                        label.setText(nameDepartments[position]);
                            //
                            //
                            //                                        return view;
                            //                                        //return super.getDropDownView(position, convertView, parent);
                            //                                    }
                            //                                };
                            //
                            //                                ?
                            //                                departmentAdapter.setDropDownViewResource(R.layout.spinner_item_layout);
                            //                                ks.setAdapter(departmentAdapter);
                            //                                try {
                            //                                    ks.setSelection(joDoc.getInt("departmentId") - 1, true);
                            //                                } catch (JSONException e) {
                            //                                    e.printStackTrace();
                            //                                }
                            //                                ks.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                            //
                            //                                    @Override
                            //                                    public void onItemSelected(
                            //                                            AdapterView<?> ksparent, View ksview,
                            //                                            int ksposition, long ksid) {
                            //                                        // TODO Auto-generated method stub
                            //                                        ksStr = ksparent.getItemAtPosition(ksposition).toString();
                            //                                        if (ksStr.equals(nameDepartments[ksposition])) {
                            //                                            try {
                            //                                                idDepartmentInt = idDepartments[ksposition];
                            //                                                joDepartmentType = joDepartments[ksposition].getJSONObject("departmentType");
                            //                                                departmentTypeTv.setText(joDepartmentType.getString("name"));
                            //                                            } catch (JSONException e) {
                            //                                                // TODO Auto-generated catch block
                            //
                            //                                                e.printStackTrace();
                            //                                            }
                            //                                        }
                            //                                    }
                            //
                            //
                            //                                    @Override
                            //                                    public void onNothingSelected(
                            //                                            AdapterView<?> arg0) {
                            //                                        // TODO Auto-generated method stub
                            //
                            //                                    }
                            //                                });
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> arg0) {
                            // TODO Auto-generated method stub

                        }
                    });
                    //                        ks.setOnTouchListener(new View.OnTouchListener() {
                    //                            @Override
                    //                            public boolean onTouch(View view, MotionEvent motionEvent) {
                    //
                    //                                Log.i(TAG, "year touch ");
                    //                                closeSoftKeyboard();
                    //                                return false;
                    //                            }
                    //                        });
                }

                @Override
                public void onNothingSelected(AdapterView<?> arg0) {
                    // TODO Auto-generated method stub

                }
            });

        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

        }
    });
    year.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub
            yearStr = parent.getItemAtPosition(position).toString();
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub
        }
    });
    month.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub
            monthStr = parent.getItemAtPosition(position).toString();
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub
        }
    });
    day.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub
            dayStr = parent.getItemAtPosition(position).toString();
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub
        }
    });
    sex.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub
            sexStr = parent.getItemAtPosition(position).toString();
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub
        }
    });

    for (int i = 0; i < sexList.size(); i++) {
        if (sexList.get(i).equals(sexStr)) {
            sex.setSelection(i, true);
            break;
        }
    }
    for (int i = 0; i < yearList.size(); i++) {
        if (yearList.get(i).equals(yearStr)) {
            year.setSelection(i, true);
            break;
        }
    }
    for (int i = 0; i < monthList.size(); i++) {
        if (monthList.get(i).equals(monthStr)) {
            month.setSelection(i, true);
            break;
        }
    }
    for (int i = 0; i < dayList.size(); i++) {
        if (dayList.get(i).equals(dayStr)) {
            day.setSelection(i, true);
            break;
        }
    }
    photoBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            picKind = 0;
            //                startActivityForResult(new Intent(ModifyInfoActivity.this, SelectPictureActivity.class), REQUEST_PICK);

            Intent intent = new Intent(ModifyInfoActivity.this, SelectPictureActivity.class);
            intent.putExtra("from", "modify");
            startActivityForResult(intent, REQUEST_PICK);
            //RegisterActivity.this.finish();
        }
    });

    signBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            picKind = 1;
            //                startActivityForResult(new Intent(ModifyInfoActivity.this, SelectPictureActivity.class), REQUEST_PICK);
            Intent intent = new Intent(ModifyInfoActivity.this, SelectPictureActivity.class);
            intent.putExtra("from", "modify");
            startActivityForResult(intent, REQUEST_PICK);
        }
    });

    regBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            modify();

        }
    });

}

From source file:com.housekeeper.ar.healthhousekeeper.RegisterActivity.java

private void setSpinner() {
    Log.i(TAG, "namePros:" + namePros);
    //      ArrayAdapter<String> proAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,namePros){
    //         @Override
    //         public View getDropDownView(int position, View convertView, ViewGroup parent) {
    //            LayoutInflater inflater=(LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    //            View view = inflater.inflate(R.layout.spinner_item_layout,
    //                  null);
    //            TextView label = (TextView) view
    //                  .findViewById(R.id.spinner_item_label);
    ///*from  w w  w.  j  a  v a 2s .c om*/
    //            label.setText(namePros[position]);
    //
    //
    //            return view;
    //            //return super.getDropDownView(position, convertView, parent);
    //         }
    //      };
    //
    //      //?
    //      proAdapter.setDropDownViewResource(R.layout.spinner_item_layout);
    ////      proAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    //      pro.setAdapter(proAdapter);
    //      pro.setOnItemSelectedListener(new OnItemSelectedListener() {
    //
    //         @Override
    //         public void onItemSelected(AdapterView<?> parent, View view,
    //                              int position, long id) {
    //            // TODO Auto-generated method stub
    //            proStr = parent.getItemAtPosition(position).toString();
    //            Log.v(TAG, "selcet proStr:" + proStr);
    //            if (proStr.equals(namePros[position])) {
    //               idJobTitlesInt = idJobTitles[position];
    //            }
    //         }
    //
    //         @Override
    //         public void onNothingSelected(AdapterView<?> arg0) {
    //            // TODO Auto-generated method stub
    //
    //         }
    //
    //      });
    //
    //      pro.setOnTouchListener(new View.OnTouchListener() {
    //         @Override
    //         public boolean onTouch(View view, MotionEvent motionEvent) {
    //
    //            Log.i(TAG, "year touch ");
    //            closeSoftKeyboard();
    //            return false;
    //         }
    //      });
    ArrayAdapter<String> shengAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item, nameProvinces) {
        @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = (LayoutInflater) getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View view = inflater.inflate(R.layout.spinner_item_layout, null);
            TextView label = (TextView) view.findViewById(R.id.spinner_item_label);

            label.setText(nameProvinces[position]);

            return view;
            //return super.getDropDownView(position, convertView, parent);
        }
    };

    //?
    shengAdapter.setDropDownViewResource(R.layout.spinner_item_layout);
    sheng.setAdapter(shengAdapter);
    sheng.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> shengparent, View shengview, int shengposition,
                long shengid) {
            // TODO Auto-generated method stub
            myApp.setShengposition(shengposition);
            shengStr = shengparent.getItemAtPosition(shengposition).toString();
            Log.v(TAG, "shengStr:" + shengStr);

            if (!shengStr.equals("") && shengStr.equals(nameProvinces[shengposition])) {
                Log.v(TAG, "position:" + shengposition);
                for (int i = 0; i < joProvinces.length; i++) {
                    try {

                        if (shengStr.equals(joProvinces[i].getString("name"))) {
                            jaCities = joProvinces[i].getJSONArray("cities");
                            joCities = new JSONObject[jaCities.length()];
                            nameCities = new String[joCities.length];

                            for (int j = 0; j < jaCities.length(); j++) {
                                joCities[j] = jaCities.getJSONObject(j);
                                nameCities[j] = joCities[j].getString("name");
                            }
                        }
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block

                        e.printStackTrace();
                    }
                }
            }
            sheng.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View view, MotionEvent motionEvent) {

                    Log.i(TAG, "year touch ");
                    closeSoftKeyboard();
                    return false;
                }
            });
            shiAdapter = new ArrayAdapter<String>(RegisterActivity.this, R.layout.spinner_item, nameCities) {
                @Override
                public View getDropDownView(int position, View convertView, ViewGroup parent) {
                    LayoutInflater inflater = (LayoutInflater) getContext()
                            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    View view = inflater.inflate(R.layout.spinner_item_layout, null);
                    TextView label = (TextView) view.findViewById(R.id.spinner_item_label);

                    label.setText(nameCities[position]);

                    return view;
                    //return super.getDropDownView(position, convertView, parent);
                }
            };

            //?
            shiAdapter.setDropDownViewResource(R.layout.spinner_item_layout);

            //            shiAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            shi.setAdapter(shiAdapter);

            shi.setOnItemSelectedListener(new OnItemSelectedListener() {

                @Override
                public void onItemSelected(AdapterView<?> shiparent, View shiview, int shiposition,
                        long shiid) {
                    // TODO Auto-generated method stub
                    shiStr = shiparent.getItemAtPosition(shiposition).toString();
                    Log.v(TAG, "shiStr:" + shiStr);
                    if (!shiStr.equals("") && shiStr.equals(nameCities[shiposition])) {
                        for (int i = 0; i < joCities.length; i++) {
                            try {
                                if (shiStr.equals(joCities[i].getString("name"))) {
                                    jaHospitals = joCities[i].getJSONArray("hospitals");
                                    joHospitals = new JSONObject[jaHospitals.length()];
                                    nameHospitals = new String[joHospitals.length];
                                    for (int j = 0; j < jaHospitals.length(); j++) {
                                        joHospitals[j] = jaHospitals.getJSONObject(j);
                                        nameHospitals[j] = joHospitals[j].getString("name");
                                    }

                                }
                            } catch (JSONException e) {
                                // TODO Auto-generated catch block

                                e.printStackTrace();
                            }
                        }
                    }
                    shi.setOnTouchListener(new View.OnTouchListener() {
                        @Override
                        public boolean onTouch(View view, MotionEvent motionEvent) {

                            Log.i(TAG, "year touch ");
                            closeSoftKeyboard();
                            return false;
                        }
                    });
                    hospitalAdapter = new ArrayAdapter<String>(RegisterActivity.this, R.layout.spinner_item,
                            nameHospitals) {
                        @Override
                        public View getDropDownView(int position, View convertView, ViewGroup parent) {
                            LayoutInflater inflater = (LayoutInflater) getContext()
                                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                            View view = inflater.inflate(R.layout.spinner_item_layout, null);
                            TextView label = (TextView) view.findViewById(R.id.spinner_item_label);

                            label.setText(nameHospitals[position]);

                            return view;
                            //return super.getDropDownView(position, convertView, parent);
                        }
                    };

                    //?
                    hospitalAdapter.setDropDownViewResource(R.layout.spinner_item_layout);
                    yy.setAdapter(hospitalAdapter);

                    yy.setOnItemSelectedListener(new OnItemSelectedListener() {

                        @Override
                        public void onItemSelected(AdapterView<?> yyparent, View yyview, int yyposition,
                                long yyid) {
                            // TODO Auto-generated method stub
                            yyStr = yyparent.getItemAtPosition(yyposition).toString();
                            if (!yyStr.equals("") && yyStr.equals(nameHospitals[yyposition])) {
                                for (int i = 0; i < joHospitals.length; i++) {
                                    try {
                                        if (yyStr.equals(joHospitals[i].getString("name"))) {
                                            jaDepartments = joHospitals[i].getJSONArray("departments");
                                            joDepartments = new JSONObject[jaDepartments.length()];
                                            nameDepartments = new String[joDepartments.length];
                                            idDepartments = new int[joDepartments.length];
                                            for (int j = 0; j < jaDepartments.length(); j++) {
                                                joDepartments[j] = jaDepartments.getJSONObject(j);
                                                nameDepartments[j] = joDepartments[j].getString("name");
                                                idDepartments[j] = joDepartments[j].getInt("id");

                                            }

                                        }
                                    } catch (JSONException e) {
                                        // TODO Auto-generated catch block

                                        e.printStackTrace();
                                    }
                                }
                            }
                            yy.setOnTouchListener(new View.OnTouchListener() {
                                @Override
                                public boolean onTouch(View view, MotionEvent motionEvent) {

                                    Log.i(TAG, "year touch ");
                                    closeSoftKeyboard();
                                    return false;
                                }
                            });
                            //                        departmentAdapter = new ArrayAdapter<String>(RegisterActivity.this, android.R.layout.simple_spinner_item, nameDepartments) {
                            //                           @Override
                            //                           public View getDropDownView(int position, View convertView, ViewGroup parent) {
                            //                              LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                            //                              View view = inflater.inflate(R.layout.spinner_item_layout,
                            //                                    null);
                            //                              TextView label = (TextView) view
                            //                                    .findViewById(R.id.spinner_item_label);
                            //
                            //                              label.setText(nameDepartments[position]);
                            //
                            //
                            //                              return view;
                            //                              //return super.getDropDownView(position, convertView, parent);
                            //                           }
                            //                        };

                            //?
                            //                        departmentAdapter.setDropDownViewResource(R.layout.spinner_item_layout);
                            //                        ks.setAdapter(departmentAdapter);
                            //                        ks.setOnItemSelectedListener(new OnItemSelectedListener() {
                            //
                            //                           @Override
                            //                           public void onItemSelected(
                            //                                 AdapterView<?> ksparent, View ksview,
                            //                                 int ksposition, long ksid) {
                            //                              // TODO Auto-generated method stub
                            //                              ksStr = ksparent.getItemAtPosition(ksposition).toString();
                            //                              if (ksStr.equals(nameDepartments[ksposition])) {
                            //                                 try {
                            //                                    idDepartmentInt = idDepartments[ksposition];
                            //                                    joDepartmentType = joDepartments[ksposition].getJSONObject("departmentType");
                            //                                    departmentTypeTv.setText(joDepartmentType.getString("name"));
                            //                                 } catch (JSONException e) {
                            //                                    // TODO Auto-generated catch block
                            //
                            //                                    e.printStackTrace();
                            //                                 }
                            //                              }
                            //                           }
                            //
                            //                           @Override
                            //                           public void onNothingSelected(
                            //                                 AdapterView<?> arg0) {
                            //                              // TODO Auto-generated method stub
                            //
                            //                           }
                            //                        });
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> arg0) {
                            // TODO Auto-generated method stub

                        }
                    });
                    //                  ks.setOnTouchListener(new View.OnTouchListener() {
                    //                     @Override
                    //                     public boolean onTouch(View view, MotionEvent motionEvent) {
                    //
                    //                        Log.i(TAG, "year touch ");
                    //                        closeSoftKeyboard();
                    //                        return false;
                    //                     }
                    //                  });
                }

                @Override
                public void onNothingSelected(AdapterView<?> arg0) {
                    // TODO Auto-generated method stub

                }
            });

        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

        }
    });

    year.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub
            yearStr = parent.getItemAtPosition(position).toString();
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub   
        }
    });
    month.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub
            monthStr = parent.getItemAtPosition(position).toString();
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub   
        }
    });
    day.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub
            dayStr = parent.getItemAtPosition(position).toString();
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub   
        }
    });
    sex.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub
            sexStr = parent.getItemAtPosition(position).toString();
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub   
        }
    });

}

From source file:foam.opensauces.StarwispBuilder.java

public void Build(final StarwispActivity ctx, final String ctxname, JSONArray arr, ViewGroup parent) {

    try {/*from  ww w .j av  a2  s  .c  om*/
        String type = arr.getString(0);

        //Log.i("starwisp","building started "+type);

        if (type.equals("build-fragment")) {
            String name = arr.getString(1);
            int ID = arr.getInt(2);
            Fragment fragment = ActivityManager.GetFragment(name);
            LinearLayout inner = new LinearLayout(ctx);
            inner.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            inner.setId(ID);
            FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction();
            fragmentTransaction.add(ID, fragment);
            fragmentTransaction.commit();
            parent.addView(inner);
            return;
        }

        if (type.equals("linear-layout")) {
            LinearLayout v = new LinearLayout(ctx);
            v.setId(arr.getInt(1));
            v.setOrientation(BuildOrientation(arr.getString(2)));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            //v.setPadding(2,2,2,2);
            JSONArray col = arr.getJSONArray(4);
            v.setBackgroundColor(Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(5);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        if (type.equals("draggable")) {
            final LinearLayout v = new LinearLayout(ctx);
            final int id = arr.getInt(1);
            v.setPadding(20, 20, 20, 20);
            v.setId(id);
            v.setOrientation(BuildOrientation(arr.getString(2)));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            v.setClickable(true);
            v.setFocusable(true);

            JSONArray col = arr.getJSONArray(4);
            v.setBackgroundResource(R.drawable.draggable);

            GradientDrawable drawable = (GradientDrawable) v.getBackground();
            final int colour = Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2));
            drawable.setColor(colour);

            parent.addView(v);
            JSONArray children = arr.getJSONArray(5);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }

            // Sets a long click listener for the ImageView using an anonymous listener object that
            // implements the OnLongClickListener interface
            /*                v.setOnLongClickListener(new View.OnLongClickListener() {
            public boolean onLongClick(View vv) {
                if (id!=99) {
                    ClipData dragData = ClipData.newPlainText("simple text", ""+id);
                    View.DragShadowBuilder myShadow = new MyDragShadowBuilder(v);
                    Log.i("starwisp","start drag id "+vv.getId());
                    v.startDrag(dragData, myShadow, null, 0);
                    v.setVisibility(View.GONE);
                    return true;
                }
                return false;
            }
                            });
            */
            // Sets a long click listener for the ImageView using an anonymous listener object that
            // implements the OnLongClickListener interface
            v.setOnTouchListener(new View.OnTouchListener() {
                public boolean onTouch(View vv, MotionEvent event) {
                    if (event.getAction() == MotionEvent.ACTION_DOWN && id != 99) {
                        //                            ClipData dragData = ClipData.newPlainText("simple text", ""+id);

                        ClipData dragData = new ClipData(
                                new ClipDescription(null, new String[] { ClipDescription.MIMETYPE_TEXT_PLAIN }),
                                new ClipData.Item("" + id));

                        View.DragShadowBuilder myShadow = new MyDragShadowBuilder(v);
                        Log.i("starwisp", "start drag id " + vv.getId());
                        v.startDrag(dragData, myShadow, null, 0);
                        v.setVisibility(View.GONE);
                        return true;
                    }
                    return false;
                }
            });

            v.setOnDragListener(new View.OnDragListener() {
                public boolean onDrag(View vv, DragEvent event) {
                    final int action = event.getAction();
                    switch (action) {
                    case DragEvent.ACTION_DRAG_STARTED:
                        if (event.getClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
                            // returns true to indicate that the View can accept the dragged data.
                            return true;
                        } else {
                            // Returns false. During the current drag and drop operation, this View will
                            // not receive events again until ACTION_DRAG_ENDED is sent.
                            return false;
                        }
                    case DragEvent.ACTION_DRAG_ENTERED: {
                        return true;
                    }
                    case DragEvent.ACTION_DRAG_LOCATION:
                        return true;
                    case DragEvent.ACTION_DRAG_EXITED: {
                        return true;
                    }
                    case DragEvent.ACTION_DROP: {
                        ClipData.Item item = event.getClipData().getItemAt(0);
                        String dragData = item.getText().toString();
                        Log.i("starwisp", "Dragged view is " + dragData);
                        int otherid = Integer.parseInt(dragData);
                        View otherw = ctx.findViewById(otherid);
                        Log.i("starwisp", "removing from parent " + ((View) otherw.getParent()).getId());

                        // check we are not adding to ourself
                        if (id != otherid) {
                            ((ViewManager) otherw.getParent()).removeView(otherw);
                            Log.i("starwisp", "adding to " + id);
                            v.addView(otherw);
                        }
                        otherw.setVisibility(View.VISIBLE);
                        return true;
                    }
                    case DragEvent.ACTION_DRAG_ENDED: {
                        if (event.getResult()) {
                        } else {
                        }
                        ;
                        return true;
                    }
                    // An unknown action type was received.
                    default:
                        Log.e("starwisp", "Unknown action type received by OnDragListener.");
                        break;
                    }
                    ;
                    return true;
                }
            });
            return;
        }

        if (type.equals("frame-layout")) {
            FrameLayout v = new FrameLayout(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        /*
        if (type.equals("grid-layout")) {
        GridLayout v = new GridLayout(ctx);
        v.setId(arr.getInt(1));
        v.setRowCount(arr.getInt(2));
        //v.setColumnCount(arr.getInt(2));
        v.setOrientation(BuildOrientation(arr.getString(3)));
        v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
                
        parent.addView(v);
        JSONArray children = arr.getJSONArray(5);
        for (int i=0; i<children.length(); i++) {
            Build(ctx,ctxname,new JSONArray(children.getString(i)), v);
        }
                
        return;
        }
        */

        if (type.equals("scroll-view")) {
            HorizontalScrollView v = new HorizontalScrollView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        if (type.equals("scroll-view-vert")) {
            ScrollView v = new ScrollView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        if (type.equals("view-pager")) {
            ViewPager v = new ViewPager(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            v.setOffscreenPageLimit(3);
            final JSONArray items = arr.getJSONArray(3);

            v.setAdapter(new FragmentPagerAdapter(ctx.getSupportFragmentManager()) {

                @Override
                public int getCount() {
                    return items.length();
                }

                @Override
                public Fragment getItem(int position) {
                    try {
                        String fragname = items.getString(position);
                        return ActivityManager.GetFragment(fragname);
                    } catch (JSONException e) {
                        Log.e("starwisp", "Error parsing data " + e.toString());
                    }
                    return null;
                }
            });
            parent.addView(v);
            return;
        }

        if (type.equals("space")) {
            // Space v = new Space(ctx); (class not found runtime error??)
            TextView v = new TextView(ctx);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
        }

        if (type.equals("image-view")) {
            ImageView v = new ImageView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));

            String image = arr.getString(2);

            if (image.startsWith("/")) {
                Bitmap bitmap = BitmapFactory.decodeFile(image);
                v.setImageBitmap(bitmap);
            } else {
                int id = ctx.getResources().getIdentifier(image, "drawable", ctx.getPackageName());
                v.setImageResource(id);
            }

            parent.addView(v);
        }

        if (type.equals("text-view")) {
            TextView v = new TextView(ctx);
            v.setId(arr.getInt(1));
            v.setText(Html.fromHtml(arr.getString(2)));
            v.setTextSize(arr.getInt(3));
            v.setMovementMethod(LinkMovementMethod.getInstance());
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            v.setClickable(false);
            v.setEnabled(false);

            v.setOnTouchListener(new View.OnTouchListener() {
                public boolean onTouch(View vv, MotionEvent event) {
                    return false;
                }
            });

            if (arr.length() > 5) {
                if (arr.getString(5).equals("left")) {
                    v.setGravity(Gravity.LEFT);
                } else {
                    if (arr.getString(5).equals("fill")) {
                        v.setGravity(Gravity.FILL);
                    } else {
                        v.setGravity(Gravity.CENTER);
                    }
                }
            } else {
                v.setGravity(Gravity.LEFT);
            }
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            parent.addView(v);
        }

        if (type.equals("debug-text-view")) {
            TextView v = (TextView) ctx.getLayoutInflater().inflate(R.layout.debug_text, null);
            //                v.setBackgroundResource(R.color.black);
            v.setId(arr.getInt(1));
            //                v.setText(Html.fromHtml(arr.getString(2)));
            //                v.setTextColor(R.color.white);
            //                v.setTextSize(arr.getInt(3));
            //                v.setMovementMethod(LinkMovementMethod.getInstance());
            //                v.setMaxLines(10);
            //                v.setVerticalScrollBarEnabled(true);
            //                v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            //v.setMovementMethod(new ScrollingMovementMethod());

            /*
            if (arr.length()>5) {
            if (arr.getString(5).equals("left")) {
                v.setGravity(Gravity.LEFT);
            } else {
                if (arr.getString(5).equals("fill")) {
                    v.setGravity(Gravity.FILL);
                } else {
                    v.setGravity(Gravity.CENTER);
                }
            }
            } else {
            v.setGravity(Gravity.LEFT);
            }
            v.setTypeface(((StarwispActivity)ctx).m_Typeface);*/
            parent.addView(v);
        }

        if (type.equals("web-view")) {
            WebView v = new WebView(ctx);
            v.setId(arr.getInt(1));
            v.setVerticalScrollBarEnabled(false);
            v.loadData(arr.getString(2), "text/html", "utf-8");
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            parent.addView(v);
        }

        if (type.equals("edit-text")) {
            final EditText v = new EditText(ctx);
            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));

            String inputtype = arr.getString(4);
            if (inputtype.equals("text")) {
                //v.setInputType(InputType.TYPE_CLASS_TEXT);
            } else if (inputtype.equals("numeric")) {
                v.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
            } else if (inputtype.equals("email")) {
                v.setInputType(InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS);
            }

            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(5)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(5);
            //v.setSingleLine(true);

            v.addTextChangedListener(new TextWatcher() {
                public void afterTextChanged(Editable s) {
                    CallbackArgs(ctx, ctxname, v.getId(), "\"" + s.toString() + "\"");
                }

                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                }

                public void onTextChanged(CharSequence s, int start, int before, int count) {
                }
            });

            parent.addView(v);
        }

        if (type.equals("button")) {
            Button v = new Button(ctx);
            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(5);
            v.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Callback(ctx, ctxname, v.getId());
                }
            });

            parent.addView(v);
        }

        if (type.equals("toggle-button")) {
            ToggleButton v = new ToggleButton(ctx);
            if (arr.getString(5).equals("fancy")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_fancy, null);
            }

            if (arr.getString(5).equals("yes")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_yes, null);
            }

            if (arr.getString(5).equals("maybe")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_maybe, null);
            }

            if (arr.getString(5).equals("no")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_no, null);
            }

            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(6);
            v.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    String arg = "#f";
                    if (((ToggleButton) v).isChecked())
                        arg = "#t";
                    CallbackArgs(ctx, ctxname, v.getId(), arg);
                }
            });
            parent.addView(v);
        }

        if (type.equals("seek-bar")) {
            SeekBar v = new SeekBar(ctx);
            v.setId(arr.getInt(1));
            v.setMax(arr.getInt(2));
            v.setProgress(arr.getInt(2) / 2);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            final String fn = arr.getString(4);

            v.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                public void onProgressChanged(SeekBar v, int a, boolean s) {
                    CallbackArgs(ctx, ctxname, v.getId(), Integer.toString(a));
                }

                public void onStartTrackingTouch(SeekBar v) {
                }

                public void onStopTrackingTouch(SeekBar v) {
                }
            });
            parent.addView(v);
        }

        if (type.equals("spinner")) {
            Spinner v = new Spinner(ctx);
            final int wid = arr.getInt(1);
            v.setId(wid);
            final JSONArray items = arr.getJSONArray(2);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            ArrayList<String> spinnerArray = new ArrayList<String>();

            for (int i = 0; i < items.length(); i++) {
                spinnerArray.add(items.getString(i));
            }

            ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<String>(ctx, R.layout.spinner_item,
                    spinnerArray) {
                public View getView(int position, View convertView, ViewGroup parent) {
                    View v = super.getView(position, convertView, parent);
                    ((TextView) v).setTypeface(((StarwispActivity) ctx).m_Typeface);
                    return v;
                }
            };

            spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_layout);

            v.setAdapter(spinnerArrayAdapter);
            v.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> a, View v, int pos, long id) {
                    try {
                        CallbackArgs(ctx, ctxname, wid, "\"" + items.getString(pos) + "\"");
                    } catch (JSONException e) {
                        Log.e("starwisp", "Error parsing data " + e.toString());
                    }
                }

                public void onNothingSelected(AdapterView<?> v) {
                }
            });

            parent.addView(v);
        }

        if (type.equals("canvas")) {
            StarwispCanvas v = new StarwispCanvas(ctx);
            final int wid = arr.getInt(1);
            v.setId(wid);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            v.SetDrawList(arr.getJSONArray(3));
            parent.addView(v);
        }

        if (type.equals("camera-preview")) {
            PictureTaker pt = new PictureTaker();
            CameraPreview v = new CameraPreview(ctx, pt);
            final int wid = arr.getInt(1);
            v.setId(wid);

            //              LinearLayout.LayoutParams lp =
            //  new LinearLayout.LayoutParams(minWidth, minHeight, 1);

            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));

            //                v.setLayoutParams(lp);
            parent.addView(v);
        }

        if (type.equals("button-grid")) {
            LinearLayout horiz = new LinearLayout(ctx);
            final int id = arr.getInt(1);
            final String buttontype = arr.getString(2);
            horiz.setId(id);
            horiz.setOrientation(LinearLayout.HORIZONTAL);
            parent.addView(horiz);
            int height = arr.getInt(3);
            int textsize = arr.getInt(4);
            LinearLayout.LayoutParams lp = BuildLayoutParams(arr.getJSONArray(5));
            JSONArray buttons = arr.getJSONArray(6);
            int count = buttons.length();
            int vertcount = 0;
            LinearLayout vert = null;

            for (int i = 0; i < count; i++) {
                JSONArray button = buttons.getJSONArray(i);

                if (vertcount == 0) {
                    vert = new LinearLayout(ctx);
                    vert.setId(0);
                    vert.setOrientation(LinearLayout.VERTICAL);
                    horiz.addView(vert);
                }
                vertcount = (vertcount + 1) % height;

                if (buttontype.equals("button")) {
                    Button b = new Button(ctx);
                    b.setId(button.getInt(0));
                    b.setText(button.getString(1));
                    b.setTextSize(textsize);
                    b.setLayoutParams(lp);
                    b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                    final String fn = arr.getString(6);
                    b.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t");
                        }
                    });
                    vert.addView(b);
                } else if (buttontype.equals("toggle")) {
                    ToggleButton b = new ToggleButton(ctx);
                    b.setId(button.getInt(0));
                    b.setText(button.getString(1));
                    b.setTextSize(textsize);
                    b.setLayoutParams(lp);
                    b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                    final String fn = arr.getString(6);
                    b.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            String arg = "#f";
                            if (((ToggleButton) v).isChecked())
                                arg = "#t";
                            CallbackArgs(ctx, ctxname, id, "" + v.getId() + " " + arg);
                        }
                    });
                    vert.addView(b);
                }
            }
        }

    } catch (JSONException e) {
        Log.e("starwisp", "Error parsing [" + arr.toString() + "] " + e.toString());
    }

    //Log.i("starwisp","building ended");

}

From source file:com.nextgis.maplibui.formcontrol.DoubleCombobox.java

@Override
public void init(JSONObject element, List<Field> fields, Bundle savedState, Cursor featureCursor,
        SharedPreferences preferences) throws JSONException {
    mSubCombobox = new Spinner(getContext());
    JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY);
    mFieldName = attributes.getString(JSON_FIELD_LEVEL1_KEY);
    mSubFieldName = attributes.getString(JSON_FIELD_LEVEL2_KEY);
    mIsShowLast = ControlHelper.isSaveLastValue(attributes);
    setEnabled(ControlHelper.isEnabled(fields, mFieldName));

    String lastValue = null;//from  w  w w.  j a  va 2s  . co  m
    String subLastValue = null;
    if (ControlHelper.hasKey(savedState, mFieldName) && ControlHelper.hasKey(savedState, mSubFieldName)) {
        lastValue = savedState.getString(ControlHelper.getSavedStateKey(mFieldName));
        subLastValue = savedState.getString(ControlHelper.getSavedStateKey(mSubFieldName));
    } else if (null != featureCursor) {
        int column = featureCursor.getColumnIndex(mFieldName);
        int subColumn = featureCursor.getColumnIndex(mSubFieldName);
        if (column >= 0)
            lastValue = featureCursor.getString(column);
        if (subColumn >= 0)
            subLastValue = featureCursor.getString(subColumn);
    } else if (mIsShowLast) {
        lastValue = preferences.getString(mFieldName, null);
        subLastValue = preferences.getString(mSubFieldName, null);
    }

    JSONArray values = attributes.optJSONArray(JSON_VALUES_KEY);
    int defaultPosition = 0;
    int lastValuePosition = -1;
    int subLastValuePosition = -1;
    mAliasValueMap = new HashMap<>();
    mSubAliasValueMaps = new HashMap<>();
    mAliasSubListMap = new HashMap<>();

    final ArrayAdapter<String> comboboxAdapter = new ArrayAdapter<>(getContext(),
            R.layout.formtemplate_double_spinner);
    setAdapter(comboboxAdapter);

    if (values != null) {
        for (int j = 0; j < values.length(); j++) {
            JSONObject keyValue = values.getJSONObject(j);
            String value = keyValue.getString(JSON_VALUE_NAME_KEY);
            String valueAlias = keyValue.getString(JSON_VALUE_ALIAS_KEY);

            Map<String, String> subAliasValueMap = new HashMap<>();
            AliasList subAliasList = new AliasList();

            mAliasValueMap.put(valueAlias, value);
            mSubAliasValueMaps.put(valueAlias, subAliasValueMap);
            mAliasSubListMap.put(valueAlias, subAliasList);
            comboboxAdapter.add(valueAlias);

            if (keyValue.has(JSON_DEFAULT_KEY) && keyValue.getBoolean(JSON_DEFAULT_KEY))
                defaultPosition = j;

            if (null != lastValue && lastValue.equals(value)) // if modify data
                lastValuePosition = j;

            JSONArray subValues = keyValue.getJSONArray(JSON_VALUES_KEY);
            for (int k = 0; k < subValues.length(); k++) {
                JSONObject subKeyValue = subValues.getJSONObject(k);
                String subValue = subKeyValue.getString(JSON_VALUE_NAME_KEY);
                String subValueAlias = subKeyValue.getString(JSON_VALUE_ALIAS_KEY);

                subAliasValueMap.put(subValueAlias, subValue);
                subAliasList.aliasList.add(subValueAlias);

                if (subKeyValue.has(JSON_DEFAULT_KEY) && subKeyValue.getBoolean(JSON_DEFAULT_KEY))
                    subAliasList.defaultPosition = k;

                if (null != subLastValue && subLastValue.equals(subValue)) { // if modify data
                    lastValuePosition = j;
                    subLastValuePosition = k;
                }
            }
        }
    }

    setSelection(lastValuePosition >= 0 ? lastValuePosition : defaultPosition);
    final int subLastValuePositionFinal = subLastValuePosition;

    // The drop down view
    comboboxAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    float minHeight = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 14,
            getResources().getDisplayMetrics());
    setPadding(0, (int) minHeight, 0, (int) minHeight);
    mSubCombobox.setPadding(0, (int) minHeight, 0, (int) minHeight);

    setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String selectedValueAlias = comboboxAdapter.getItem(position);
            AliasList subAliasList = mAliasSubListMap.get(selectedValueAlias);

            ArrayAdapter<String> subComboboxAdapter = new ArrayAdapter<>(view.getContext(),
                    R.layout.formtemplate_double_spinner, subAliasList.aliasList);
            subComboboxAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

            mSubCombobox.setAdapter(subComboboxAdapter);
            mSubCombobox.setSelection(mFirstShow && subLastValuePositionFinal >= 0 ? subLastValuePositionFinal
                    : subAliasList.defaultPosition);

            if (mFirstShow) {
                mFirstShow = false;
            }
        }

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

From source file:com.ezac.gliderlogs.FlightOverviewActivity.java

public void DoFlightMember() {
    // get member_list.xml view
    LayoutInflater li = LayoutInflater.from(context);
    membersView = li.inflate(R.layout.member_list, null);

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
    // set member_list.xml to alertdialog builder
    alertDialogBuilder.setView(membersView);
    ////  ww  w  .  j a v  a  2  s .c o m
    Button mMember_Btn;
    final EditText mDetailInfo;
    Button mGlider_Btn;
    // set dialog message
    alertDialogBuilder.setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            String fRegi = (String) mGliderSpin.getSelectedItem();
            String fPilo = (String) mMemberSpin.getSelectedItem();
            if (!fPilo.equals("") && !fRegi.equals("")) {
                String fRegiPilo = "";
                for (int i = 0; i < mGliderSpin.getCount(); i++) {
                    String s = (String) mGliderSpin.getItemAtPosition(i);
                    if (s.equalsIgnoreCase(fRegi)) {
                        fRegiPilo = GliderList.get(i);
                    }
                }
                for (int i = 0; i < mMemberSpin.getCount(); i++) {
                    String s = (String) mMemberSpin.getItemAtPosition(i);
                    if (s.equalsIgnoreCase(fPilo)) {
                        fRegiPilo = fRegiPilo + ":" + MemberIndexList.get(i);
                    }
                }
                DoFlightFilter(7, fRegiPilo);
                OptionSelect(R.id.action_my, R.id.action_all, R.id.action_open, R.id.action_ready,
                        R.id.action_45min);
            } else if (!fRegi.equals("")) {
                for (int i = 0; i < mGliderSpin.getCount(); i++) {
                    String s = (String) mGliderSpin.getItemAtPosition(i);
                    if (s.equalsIgnoreCase(fRegi)) {
                        // set filter criteria for selected member
                        DoFlightFilter(6, GliderList.get(i));
                        OptionSelect(R.id.action_my, R.id.action_all, R.id.action_open, R.id.action_ready,
                                R.id.action_45min);
                    }
                }
            } else if (!fPilo.equals("")) {
                for (int i = 0; i < mMemberSpin.getCount(); i++) {
                    String s = (String) mMemberSpin.getItemAtPosition(i);
                    if (s.equalsIgnoreCase(fPilo)) {
                        // set filter criteria for selected member
                        DoFlightFilter(5, MemberIndexList.get(i));
                        OptionSelect(R.id.action_my, R.id.action_all, R.id.action_open, R.id.action_ready,
                                R.id.action_45min);
                    }
                }
            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            DoFlightFilter(4, "");
            OptionSelect(R.id.action_all, R.id.action_my, R.id.action_open, R.id.action_ready,
                    R.id.action_45min);
            dialog.cancel();
        }
    });
    AlertDialog alertDialog = alertDialogBuilder.create();
    // get reference to and fill spinner with members
    mMemberSpin = (Spinner) membersView.findViewById(R.id.flight_member);
    ArrayAdapter<String> dataAdapter_1 = new ArrayAdapter<String>(FlightOverviewActivity.this,
            android.R.layout.simple_spinner_item, MemberList);
    dataAdapter_1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mMemberSpin.setAdapter(dataAdapter_1);
    // get reference to and fill spinner with gliders
    mGliderSpin = (Spinner) membersView.findViewById(R.id.flight_glider);
    ArrayAdapter<String> dataAdapter_2 = new ArrayAdapter<String>(FlightOverviewActivity.this,
            android.R.layout.simple_spinner_item, GliderList);
    dataAdapter_2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mGliderSpin.setAdapter(dataAdapter_2);
    mDetailInfo = (EditText) membersView.findViewById(R.id.editText1);
    // make field read only
    mDetailInfo.setClickable(false);
    mDetailInfo.setFocusable(false);
    mGlider_Btn = (Button) membersView.findViewById(R.id.flight_glider_detail);
    mGlider_Btn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            String fRegi = (String) mGliderSpin.getSelectedItem();
            if (fRegi.equals(null) || fRegi.equals("")) {
                mDetailInfo.setText("Geen Registratie selectie gevonden,\nmaak een keuze !");
            } else {
                String fRegiPilo = "";
                for (int i = 0; i < mGliderSpin.getCount(); i++) {
                    String s = (String) mGliderSpin.getItemAtPosition(i);
                    if (s.equalsIgnoreCase(fRegi)) {
                        fRegiPilo = GliderList.get(i);
                    }
                }
                mDetailInfo.setText(getDetailInfo(FlightsContentProvider.CONTENT_URI_GLIDER, fRegiPilo, 0));
            }
        }
    });
    mMember_Btn = (Button) membersView.findViewById(R.id.flight_member_detail);
    mMember_Btn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            String fPilo = (String) mMemberSpin.getSelectedItem();
            if (fPilo.equals(null) || fPilo.equals("")) {
                mDetailInfo.setText("Geen Naam selectie gevonden,\nmaak een keuze !");
            } else {
                String fRegiPilo = "";
                for (int i = 0; i < mMemberSpin.getCount(); i++) {
                    String s = (String) mMemberSpin.getItemAtPosition(i);
                    if (s.equalsIgnoreCase(fPilo)) {
                        fRegiPilo = MemberIndexList.get(i);
                    }
                }
                mDetailInfo.setText(getDetailInfo(FlightsContentProvider.CONTENT_URI_MEMBER, fRegiPilo, 1));
            }
        }
    });
    alertDialog.show();
}

From source file:cl.gisred.android.PowerOnActivity.java

public void dialogBusqueda() {

    AlertDialog.Builder dialogBusqueda = new AlertDialog.Builder(this);
    dialogBusqueda.setTitle("Busqueda");
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View v = inflater.inflate(R.layout.dialog_busqueda, null);
    dialogBusqueda.setView(v);//ww w  .j ava 2  s. com

    Spinner spinner = (Spinner) v.findViewById(R.id.spinnerBusqueda);
    final LinearLayout llBuscar = (LinearLayout) v.findViewById(R.id.llBuscar);
    final LinearLayout llDireccion = (LinearLayout) v.findViewById(R.id.llBuscarDir);
    final LinearLayout llOrden = (LinearLayout) v.findViewById(R.id.llBuscarOrden);

    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this,
            R.layout.support_simple_spinner_dropdown_item, searchArray);

    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            SpiBusqueda = position;

            if (position == 6) {
                if (llDireccion != null)
                    llDireccion.setVisibility(View.GONE);
                if (llBuscar != null)
                    llBuscar.setVisibility(View.GONE);
                if (llOrden != null)
                    llOrden.setVisibility(View.VISIBLE);
            } else if (position == 4) {
                if (llBuscar != null)
                    llBuscar.setVisibility(View.GONE);
                if (llOrden != null)
                    llOrden.setVisibility(View.GONE);
                if (llDireccion != null)
                    llDireccion.setVisibility(View.VISIBLE);
            } else {
                if (llDireccion != null)
                    llDireccion.setVisibility(View.GONE);
                if (llOrden != null)
                    llOrden.setVisibility(View.GONE);
                if (llBuscar != null)
                    llBuscar.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            Toast.makeText(getApplicationContext(), "Nada seleccionado", Toast.LENGTH_SHORT).show();
        }
    });

    final EditText eSearch = (EditText) v.findViewById(R.id.txtBuscar);
    final EditText eStreet = (EditText) v.findViewById(R.id.txtCalle);
    final EditText eNumber = (EditText) v.findViewById(R.id.txtNum);
    final EditText eOrder = (EditText) v.findViewById(R.id.txtOrden);

    dialogBusqueda.setPositiveButton("Buscar", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

            if (SpiBusqueda == 4) {
                txtBusqueda = new String();
                if (!eStreet.getText().toString().isEmpty())
                    txtBusqueda = (eNumber.getText().toString().trim().isEmpty()) ? "0 "
                            : eNumber.getText().toString().trim() + " ";
                txtBusqueda = txtBusqueda + eStreet.getText().toString();
            } else if (SpiBusqueda == 6) {
                txtBusqueda = eOrder.getText().toString() + "-1";
            } else {
                txtBusqueda = eSearch.getText().toString();
            }

            if (txtBusqueda.trim().isEmpty()) {
                Toast.makeText(myMapView.getContext(), "Debe ingresar un valor", Toast.LENGTH_SHORT).show();
            } else {
                // Escala de calle para busquedas por default

                iBusqScale = 4000;
                switch (SpiBusqueda) {
                case 0:
                    callQuery(txtBusqueda, getValueByEmp("CLIENTES_XY_006.nis"),
                            LyCLIENTES.getUrl().concat("/0"));
                    if (LyCLIENTES.getLayers() != null && LyCLIENTES.getLayers().length > 0)
                        iBusqScale = LyCLIENTES.getLayers()[0].getLayerServiceInfo().getMinScale();
                    break;
                case 1:
                    callQuery(txtBusqueda, "codigo", LySED.getUrl().concat("/1"));
                    if (LySED.getLayers() != null && LySED.getLayers().length > 1)
                        iBusqScale = LySED.getLayers()[1].getLayerServiceInfo().getMinScale();
                    break;
                case 2:
                    callQuery(txtBusqueda, "rotulo", LyPOSTES.getUrl().concat("/0"));
                    if (LyPOSTES.getLayers() != null && LyPOSTES.getLayers().length > 0)
                        iBusqScale = LyPOSTES.getLayers()[0].getLayerServiceInfo().getMinScale();
                    break;
                case 3:
                    callQuery(txtBusqueda, "serie_medidor", LyMEDIDORES.getUrl().concat("/1"));
                    if (LyMEDIDORES.getLayers() != null && LyMEDIDORES.getLayers().length > 1)
                        iBusqScale = LyMEDIDORES.getLayers()[1].getLayerServiceInfo().getMinScale();
                    break;
                case 4:
                    iBusqScale = 5000;
                    String[] sBuscar = { eStreet.getText().toString(), eNumber.getText().toString() };
                    String[] sFields = { "nombre_calle", "numero" };
                    callQuery(sBuscar, sFields, LyDIRECCIONES.getUrl().concat("/0"));
                    break;
                case 5:
                    callQuery(txtBusqueda, new String[] { "id_equipo", "nombre" },
                            LyEQUIPOSLINEA.getUrl().concat("/0"));
                    if (LyEQUIPOSLINEA.getLayers() != null && LyEQUIPOSLINEA.getLayers().length > 0)
                        iBusqScale = LyEQUIPOSLINEA.getLayers()[0].getLayerServiceInfo().getMinScale();
                    break;
                case 6:
                    callQuery(txtBusqueda, getValueByEmp("ARCGIS.dbo.POWERON_CLIENTES.id_orden"),
                            LyPOCLIENTES.getUrl().concat("/1"));
                    if (LyPOCLIENTES.getLayers() != null && LyPOCLIENTES.getLayers().length > 0)
                        if (LyPOCLIENTES.getLayers()[1].getLayerServiceInfo().getMinScale() > 0)
                            iBusqScale = LyPOCLIENTES.getLayers()[1].getLayerServiceInfo().getMinScale();
                    break;
                case 7:
                    callQueryInt(txtBusqueda, getValueByEmp("ARCGIS.dbo.POWERON_CLIENTES.id_incidencia"),
                            LyPOCLIENTES.getUrl().concat("/1"));
                    if (LyPOCLIENTES.getLayers() != null && LyPOCLIENTES.getLayers().length > 0)
                        if (LyPOCLIENTES.getLayers()[1].getLayerServiceInfo().getMinScale() > 0)
                            iBusqScale = LyPOCLIENTES.getLayers()[1].getLayerServiceInfo().getMinScale();
                    break;
                }
            }
        }
    });

    dialogBusqueda.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

        }
    });

    dialogBusqueda.show();
}