Example usage for android.widget Spinner Spinner

List of usage examples for android.widget Spinner Spinner

Introduction

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

Prototype

public Spinner(Context context) 

Source Link

Document

Constructs a new spinner with the given context's theme.

Usage

From source file:com.manning.androidhacks.hack017.CreateAccountAdapter.java

private void populateThirdForm(LinearLayout formLayout) {
    formLayout.addView(createTitle(mContext.getString(R.string.account_create_city_title)));
    EditText cityEditText = createEditText(mContext.getString(R.string.account_create_city_hint),
            InputType.TYPE_CLASS_TEXT, EditorInfo.IME_ACTION_DONE, false, CITY_KEY);

    if (mFormData.get(CITY_KEY) != null) {
        cityEditText.setText(mFormData.get(CITY_KEY));
    }//  w  w w . j  a  va 2  s .  c  o m

    formLayout.addView(cityEditText);
    formLayout.addView(createErrorView(CITY_KEY));

    formLayout.addView(createTitle(mContext.getString(R.string.account_create_country_title)));

    Spinner spinner = new Spinner(mContext);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);
    params.bottomMargin = 17;
    spinner.setLayoutParams(params);

    final ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext,
            android.R.layout.simple_spinner_item, Countries.COUNTRIES);
    spinner.setAdapter(adapter);
    spinner.setPrompt(mContext.getString(R.string.account_create_country_spinner_prompt));
    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {

            mFormData.put(COUNTRY_KEY, Countries.COUNTRY_CODES[pos]);
        }

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

    if (mFormData.get(COUNTRY_KEY) != null) {
        List<String> array = Arrays.asList(Countries.COUNTRY_CODES);
        spinner.setSelection(array.indexOf(mFormData.get(COUNTRY_KEY)));
    }

    formLayout.addView(spinner);
}

From source file:pl.wasat.smarthma.ui.frags.base.BaseCollectionDetailsFragment.java

@NonNull
private Spinner buildSpinnerView(final Parameter param) {
    Spinner spinner = new Spinner(getActivity());
    spinner.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT,
            TableLayout.LayoutParams.WRAP_CONTENT, 1f));
    spinner.setPadding(20, 0, 20, 0);//w  w  w. ja v  a2 s  . co  m

    final List<String> optList = new ArrayList<>();
    optList.add(String.format(getContext().getString(R.string.choose_osdd_param), param.getName()));
    for (Option opt : param.getOptions()) {
        optList.add(opt.getLabel());
    }

    ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getActivity(), R.layout.spinner_item_slider,
            optList);
    spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(spinnerAdapter);

    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            String optValue = "";
            if (l > 0) {
                optValue = param.getOptions().get(i - 1).getValue();
                checkParamType(param, optValue);
            }
            fedeoRequestParams.addOsddValue(param.getValue(), optValue);
        }

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

    });
    return spinner;
}

From source file:com.github.vseguip.sweet.contacts.SweetConflictResolveActivity.java

/**
 * @param fieldTable//from ww w .j  ava  2s  . c o  m
 * @param nameOfField
 * @param field
 */
private void addConflictRow(TableLayout fieldTable, final String nameOfField, final String fieldLocal,
        final String fieldRemote) {
    if (mCurrentLocal == null || mCurrentSugar == null)
        return;
    // String fieldLocal = mCurrentLocal.get(nameOfField);
    // String fieldRemote = mCurrentSugar.get(nameOfField);
    TableRow row = new TableRow(this);
    final Spinner sourceSelect = new Spinner(this);
    sourceSelect.setBackgroundResource(R.drawable.black_underline);
    ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, this.getResources().getStringArray(R.array.conflict_sources));
    spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    sourceSelect.setAdapter(spinnerArrayAdapter);
    // Open the spinner when pressing any of the text fields
    OnClickListener spinnerOpener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            sourceSelect.performClick();
        }
    };
    row.addView(sourceSelect);
    fieldTable.addView(row);
    row = new TableRow(this);
    TextView fieldName = new TextView(this);
    int stringId = this.getResources().getIdentifier(nameOfField, "string", this.getPackageName());
    fieldName.setText(this.getString(stringId));
    fieldName.setTextSize(16);
    fieldName.setPadding(fieldName.getPaddingLeft(), fieldName.getPaddingTop(),
            fieldName.getPaddingRight() + 10, fieldName.getPaddingBottom());
    fieldName.setOnClickListener(spinnerOpener);
    row.addView(fieldName);
    final TextView fieldValueLocal = new TextView(this);
    fieldValueLocal.setText(fieldLocal);
    fieldValueLocal.setTextSize(16);
    row.addView(fieldValueLocal);
    fieldValueLocal.setOnClickListener(spinnerOpener);

    fieldTable.addView(row);
    row = new TableRow(this);
    row.addView(new TextView(this));// add dummy control
    final TextView fieldValueRemote = new TextView(this);
    fieldValueRemote.setText(fieldRemote);
    fieldValueRemote.setTextSize(16);

    fieldValueRemote.setOnClickListener(spinnerOpener);
    row.addView(fieldValueRemote);
    sourceSelect.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0) {
                fieldValueLocal.setTextAppearance(SweetConflictResolveActivity.this, R.style.textSelected);
                fieldValueRemote.setTextAppearance(SweetConflictResolveActivity.this, R.style.textUnselected);
                resolvedContacts[mPosResolved].set(nameOfField, fieldLocal);
            } else {
                fieldValueLocal.setTextAppearance(SweetConflictResolveActivity.this, R.style.textUnselected);
                fieldValueRemote.setTextAppearance(SweetConflictResolveActivity.this, R.style.textSelected);
                resolvedContacts[mPosResolved].set(nameOfField, fieldRemote);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> view) {
        }
    });
    row.setPadding(row.getLeft(), row.getTop() + 5, row.getRight(), row.getBottom() + 10);
    // Restore appropiate selections according to resolved contact
    if (resolvedContacts[mPosResolved].get(nameOfField).equals(fieldLocal)) {
        sourceSelect.setSelection(0);
    } else {
        sourceSelect.setSelection(1);
    }
    fieldTable.addView(row);
}

From source file:com.ichi2.anki.ModelBrowser.java

private void addNewNoteTypeDialog() {

    String add = getResources().getString(R.string.model_browser_add_add);
    String clone = getResources().getString(R.string.model_browser_add_clone);

    // AnkiDroid doesn't have stdmodels class or model name localization, this could be much cleaner if implemented
    final String basicName = "Basic";
    final String addForwardReverseName = "Basic (and reversed card)";
    final String addForwardOptionalReverseName = "Basic (optional reversed card)";
    final String addClozeModelName = "Cloze";

    //Populates arrayadapters listing the mModels (includes prefixes/suffixes)
    mNewModelLabels = new ArrayList<>();

    //Used to fetch model names
    mNewModelNames = new ArrayList<>();
    mNewModelLabels.add(String.format(add, basicName));
    mNewModelLabels.add(String.format(add, addForwardReverseName));
    mNewModelLabels.add(String.format(add, addForwardOptionalReverseName));
    mNewModelLabels.add(String.format(add, addClozeModelName));

    mNewModelNames.add(basicName);/*from   w w  w.j  a va2s  .co  m*/
    mNewModelNames.add(addForwardReverseName);
    mNewModelNames.add(addForwardOptionalReverseName);
    mNewModelNames.add(addClozeModelName);

    final int numStdModels = mNewModelLabels.size();

    if (mModels != null) {
        for (JSONObject model : mModels) {
            try {
                mNewModelLabels.add(String.format(clone, model.getString("name")));
                mNewModelNames.add(model.getString("name"));
            } catch (JSONException e) {
                throw new RuntimeException(e);
            }
        }
    }

    final Spinner addSelectionSpinner = new Spinner(this);
    ArrayAdapter<String> mNewModelAdapter = new ArrayAdapter<>(this, R.layout.dropdown_deck_item,
            mNewModelLabels);

    addSelectionSpinner.setAdapter(mNewModelAdapter);

    new MaterialDialog.Builder(this).title(R.string.model_browser_add).positiveText(R.string.dialog_ok)
            .customView(addSelectionSpinner, true).callback(new MaterialDialog.ButtonCallback() {
                @Override
                public void onPositive(MaterialDialog dialog) {
                    mModelNameInput = new EditText(ModelBrowser.this);
                    mModelNameInput.setSingleLine();

                    //Temporary workaround - Lack of stdmodels class
                    if (addSelectionSpinner.getSelectedItemPosition() < numStdModels) {
                        mModelNameInput.setText(randomizeName(
                                mNewModelNames.get(addSelectionSpinner.getSelectedItemPosition())));
                    } else {
                        mModelNameInput
                                .setText(mNewModelNames.get(addSelectionSpinner.getSelectedItemPosition()) + " "
                                        + getResources().getString(R.string.model_clone_suffix));
                    }

                    mModelNameInput.setSelection(mModelNameInput.getText().length());

                    //Create textbox to name new model
                    new MaterialDialog.Builder(ModelBrowser.this).title(R.string.model_browser_add)
                            .positiveText(R.string.dialog_ok).customView(mModelNameInput, true)
                            .callback(new MaterialDialog.ButtonCallback() {
                                @Override
                                public void onPositive(MaterialDialog dialog) {
                                    String modelName = mModelNameInput.getText().toString();
                                    addNewNoteType(modelName, addSelectionSpinner.getSelectedItemPosition());
                                }
                            }).negativeText(R.string.dialog_cancel).show();
                }
            }).negativeText(R.string.dialog_cancel).show();
}

From source file:it.ielettronica.TVS.MyListAdapterExt.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    //If there's no recycled view, inflate one and tag each of the views
    //you'll want to modify later
    //Log.d("Inside", "GetView");

    plv = null;/*from   w  ww.  j  a  v  a 2s  .  com*/
    if (convertView == null) {

        convertView = mInflater.inflate(R.layout.row_site_remote, parent, false);
        plv = new PlaylistValues();

        plv.nameTxt = (TextView) convertView.findViewById(R.id.nameTxt);
        plv.aboutTxt = (TextView) convertView.findViewById(R.id.aboutTxt);
        plv.iconImg = (ImageView) convertView.findViewById(R.id.iconImg);
        plv.btnPlayLocal = (Button) convertView.findViewById(R.id.btnPlayLocal);
        plv.indicator = (ProgressBar) convertView.findViewById(R.id.progress);
        plv.btnAddLocal = (Button) convertView.findViewById(R.id.btnAddLocal);
        plv.imageState = (ImageView) convertView.findViewById(R.id.imgState);
        plv.btnEditDel = (Button) convertView.findViewById(R.id.btnEditDel);
        //This assumes layout/row_left.xml includes a TextView with an id of "textview"
        convertView.setTag(plv);
    } else {
        plv = (PlaylistValues) convertView.getTag();
    }

    //Initially we want the progress indicator visible, and the image invisible
    plv.indicator.setVisibility(View.VISIBLE);
    plv.iconImg.setVisibility(View.INVISIBLE);

    if (MainActivity.isAmministrator()) {
        plv.btnEditDel.setVisibility(View.VISIBLE);
    } else {
        plv.btnEditDel.setVisibility(View.INVISIBLE);
    }

    //Retrieve the tagged view, get the item for that position, and
    //update the text

    ImageLoadingListener listener = new ImageLoadingListener() {

        @Override
        public void onLoadingStarted(String arg0, View arg1) {
            // TODO Auto-generated method stub
            plv.indicator.setVisibility(View.INVISIBLE);
            plv.iconImg.setVisibility(View.VISIBLE);

        }

        @Override
        public void onLoadingCancelled(String arg0, View arg1) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) {
            //plv.indicator.setVisibility(View.INVISIBLE);
            //plv.iconImg.setVisibility(View.VISIBLE);
        }

        @Override
        public void onLoadingFailed(String arg0, View arg1, FailReason arg2) {
            // TODO Auto-generated method stub

        }

    };

    stk = mItems.get(position);
    plv.nameTxt.setText(stk.getName());
    plv.aboutTxt.setText(stk.getAbout());

    String uri = "@drawable/myresource"; // where myresource.png is the file
    // extension removed from the String

    if (MainActivity.isAmministrator() == Boolean.TRUE) {
        Drawable res;
        if (stk.getAccepted() == 1) {
            res = ContextCompat.getDrawable(MainActivity.getAppContext(), R.drawable.good);
        } else {
            res = ContextCompat.getDrawable(MainActivity.getAppContext(), R.drawable.warning);
        }
        plv.imageState.setImageDrawable(res);
    }

    imageLoader.displayImage(stk.getImgUrl(), plv.iconImg, options, listener);

    plv.btnEditDel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            final StackSite stkloc = mItems.get(position);
            MainActivity.posRemoteListBeforeExecuted = sitesMusic.getFirstVisiblePosition();
            Intent intent = new Intent(MainActivity.getAppContext(), ModChannel.class);

            intent.putExtra("TitleChannel", stkloc.getName());
            intent.putExtra("DescrChannel", stkloc.getAbout());
            intent.putExtra("IconChannel", stkloc.getImgUrl());
            intent.putExtra("isAccepted", stkloc.getAccepted());
            intent.putExtra("NameGroup", GroupVSeletced.getGroupName());
            intent.putExtra("LevelGroup", GroupVSeletced.getGroupLevel());
            intent.putExtra("TypeGroup", GroupVSeletced.getGroupType());

            intent.putExtra("GroupLevel", GroupVSeletced.getGroupLevel());
            tabFromDB.fa.startActivity(intent);

        }
    });

    plv.btnPlayLocal.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            //                final Intent intent = new Intent(v.getContext(), MediaPlayerDemo_Video.class);
            final StackSite stkloc = mItems.get(position);
            MainActivity.posRemoteListBeforeExecuted = sitesMusic.getFirstVisiblePosition();

            GroupType = GroupVSeletced.getGroupType();

            RemoteCommunications rm = new RemoteCommunications();
            List<StackLink> Links = new ArrayList<StackLink>();
            rm.getLinks(Links, stkloc.getName(), new GetLinkCallback() {
                @Override
                public void done(List<StackLink> returnedLinks) {
                    List<StackLink> Links = returnedLinks;
                    if (Links.size() == 1) {
                        MainActivity.posLocalListBeforeExecuted = tabFromDB.sitesMusic
                                .getFirstVisiblePosition();
                        if (MainActivity.isAmministrator()) {

                            Intent intent = new Intent(MainActivity.getAppContext(), LinksLists.class);
                            intent.putExtra("VideoStreamName", stkloc.getName());
                            intent.putExtra("GroupType", GroupType);

                            tabFromDB.fa.startActivity(intent);

                        } else {
                            String linkVal = Links.get(0).getLinkValue();
                            //Uri myUri = Uri.parse(linkVal);

                            if (GroupType == 0) {

                                Intent mpdIntent = new Intent(tabLocal.Fa.getContext(), PlayerActivity.class)
                                        .setData(Uri.parse(linkVal))
                                        .putExtra(PlayerActivity.CONTENT_ID_EXTRA, "")
                                        .putExtra(PlayerActivity.CONTENT_TYPE_EXTRA, PlayerActivity.TYPE_HLS)
                                        .putExtra(PlayerActivity.PROVIDER_EXTRA, "");
                                tabFromDB.fa.getContext().startActivity(mpdIntent);

                            } else if (GroupType == 1) {

                                //                                    Intent intent2 = new Intent(tabLocal.Fa.getContext(), MediaPlayerDemo_VideoView.class);
                                //                                    intent2.putExtra("pathValue", linkVal);
                                //                                    tabFromDB.fa.getContext().startActivity(intent2);

                            } else {

                                //                                    intent.putExtra("media", 5);
                                //                                    intent.putExtra("pathValue", linkVal);
                                //
                                //                                    try {
                                //                                        tabFromDB.fa.startActivity(intent);
                                //                                    } catch (Exception ex) {
                                //                                        Toast.makeText(cloc, ex.toString(),
                                //                                                Toast.LENGTH_SHORT).show();
                                //                                    }

                            }

                            Toast.makeText(cloc, "Play: " + stkloc.getName(), Toast.LENGTH_SHORT).show();

                        }

                    } else if (Links.size() == 0) {
                        Toast.makeText(cloc,
                                "the channel:  '" + stkloc.getName() + "' doesn't have any link associated",
                                Toast.LENGTH_SHORT).show();
                    } else {

                        Intent intent = new Intent(MainActivity.getAppContext(), LinksLists.class);
                        intent.putExtra("VideoStreamName", stkloc.getName());
                        tabFromDB.fa.startActivity(intent);

                    }
                }
            });

        }
    });

    plv.btnAddLocal.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            stkloc = mItems.get(position);

            RemoteCommunications rm = new RemoteCommunications();
            List<StackLink> Links = new ArrayList<StackLink>();
            rm.getLinks(Links, stkloc.getName(), new GetLinkCallback() {
                @Override
                public void done(List<StackLink> returnedLinks) {

                    AlertDialog.Builder alertDialog;
                    try {
                        alertDialog = new AlertDialog.Builder(tabFromDB.fa.getContext());
                    } catch (Exception ex) {
                        alertDialog = new AlertDialog.Builder(MainActivity.getAppContext());
                    }

                    retLinks = returnedLinks;
                    LinearLayout layout = new LinearLayout(MainActivity.getAppContext());
                    layout.setOrientation(LinearLayout.VERTICAL);

                    if (returnedLinks.size() > 1) {

                        LinearLayout rlayoutLink = new LinearLayout(MainActivity.getAppContext());
                        rlayoutLink.setOrientation(LinearLayout.HORIZONTAL);
                        final TextView textView = new TextView(MainActivity.getAppContext());
                        textView.setText("Links:  ");
                        textView.setGravity(Gravity.RIGHT);
                        textView.setLayoutParams(
                                new FrameLayout.LayoutParams(400, LinearLayout.LayoutParams.WRAP_CONTENT));
                        rlayoutLink.addView(textView);
                        listLinks = new Spinner(MainActivity.getAppContext());

                        List<String> retLinksString = new ArrayList<String>();
                        for (int i = 0; i < returnedLinks.size(); i++) {
                            retLinksString.add(returnedLinks.get(i).getLinkTxt());
                        }

                        listLinks.setAdapter(new MyCustomAdapter(MainActivity.getAppContext(),
                                R.layout.rowspinnertake, retLinksString, returnedLinks));

                        //ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.getAppContext(), android.R.layout.simple_spinner_item, retLinksString);
                        //adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                        //listLinks.setAdapter(adapter);

                        listLinks.setLayoutParams(
                                new FrameLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                                        LinearLayout.LayoutParams.WRAP_CONTENT));

                        rlayoutLink.addView(listLinks);
                        layout.addView(rlayoutLink);
                    }

                    final Button btnAddToTheEnd = new Button(MainActivity.getAppContext());
                    btnAddToTheEnd.setText("Add");

                    btnAddToTheEnd.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {

                            StackSite stkloc = mItems.get(position);

                            if (listLinks != null) {
                                posSpinnerLink = listLinks.getSelectedItemPosition();
                            } else {
                                posSpinnerLink = 0;
                            }

                            if (retLinks.size() == 0) {
                                Toast.makeText(cloc,
                                        "the channel:  '" + stkloc.getName()
                                                + "' doesn't have any link associated",
                                        Toast.LENGTH_SHORT).show();
                            } else {

                                String url;

                                if (retLinks.size() == 1) {

                                    url = retLinks.get(0).getLinkValue();

                                } else {
                                    url = retLinks.get(posSpinnerLink).getLinkValue();
                                }

                                stkloc.setLink(url);
                                stkloc.setTypeStream(GroupVSeletced.getGroupType());
                                stkloc.setStaticName(stkloc.getName());
                                String nameStation = stkloc.getName();
                                stkloc.setOrigin(0);
                                boolean isAdded = dbHandler.addSite(stkloc);
                                if (isAdded) {
                                    Toast.makeText(MainActivity.getAppContext(),
                                            nameStation + " is added in Local Playlist", Toast.LENGTH_SHORT)
                                            .show();
                                }
                                List<StackSite> itemsLocal;
                                itemsLocal = dbHandler.getStackSites();
                                if (itemsLocal.size() == 0) {
                                    tabLocal.editEmptyLocalList.setVisibility(View.VISIBLE);
                                } else {
                                    tabLocal.editEmptyLocalList.setVisibility(View.INVISIBLE);
                                }

                                tabLocal.sitesLocal.setCheeseList(itemsLocal);
                                tabLocal.sitesLocal.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
                                StableArrayAdapter adapterLocal = new StableArrayAdapter(
                                        tabLocal.Fa.getContext(), R.layout.row_site_local, itemsLocal);
                                tabLocal.sitesLocal.setAdapter(adapterLocal);

                                OptionDialog.dismiss();

                            }

                        }
                    });
                    btnAddToTheEnd.setLayoutParams(
                            new FrameLayout.LayoutParams(400, LinearLayout.LayoutParams.WRAP_CONTENT));
                    layout.addView(btnAddToTheEnd);

                    final Button btnAddAfter = new Button(MainActivity.getAppContext());
                    final Spinner listChannelAlreadyAdded = new Spinner(MainActivity.getAppContext());
                    List<String> ListNameChannel;
                    ListNameChannel = dbHandler.getNamesFromStackSites();
                    ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(MainActivity.getAppContext(),
                            android.R.layout.simple_spinner_item, ListNameChannel);
                    adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                    listChannelAlreadyAdded.setAdapter(adapter2);
                    posSpinner = listChannelAlreadyAdded.getSelectedItemPosition();

                    if (posSpinner != -1) {
                        LinearLayout rlayout = new LinearLayout(MainActivity.getAppContext());
                        rlayout.setOrientation(LinearLayout.HORIZONTAL);

                        btnAddAfter.setText("Add Before");
                        btnAddAfter.setOnClickListener(new View.OnClickListener() {
                            public void onClick(View v) {

                                if (listLinks != null) {
                                    posSpinnerLink = listLinks.getSelectedItemPosition();
                                } else {
                                    posSpinnerLink = 0;
                                }

                                StackSite stkloc = mItems.get(position);

                                if (retLinks.size() == 0) {
                                    Toast.makeText(cloc,
                                            "the channel:  '" + stkloc.getName()
                                                    + "' doesn't have any link associated",
                                            Toast.LENGTH_SHORT).show();
                                } else {

                                    String url;

                                    if (retLinks.size() == 1) {

                                        url = retLinks.get(0).getLinkValue();

                                    } else {
                                        url = retLinks.get(posSpinnerLink).getLinkValue();
                                    }

                                    stkloc.setLink(url);
                                    stkloc.setOrigin(0);
                                    stkloc.setTypeStream(GroupVSeletced.getGroupType());
                                    String nameStation = stkloc.getName();
                                    posSpinner = listChannelAlreadyAdded.getSelectedItemPosition();

                                    boolean isAdded = dbHandler.addSiteBefore(stkloc, posSpinner);
                                    if (isAdded) {
                                        Toast.makeText(MainActivity.getAppContext(),
                                                nameStation + " is added in Local Playlist", Toast.LENGTH_SHORT)
                                                .show();
                                    }
                                    List<StackSite> itemsLocal;
                                    itemsLocal = dbHandler.getStackSites();
                                    tabLocal.sitesLocal.setCheeseList(itemsLocal);
                                    tabLocal.sitesLocal.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
                                    StableArrayAdapter adapterLocal = new StableArrayAdapter(
                                            tabLocal.Fa.getContext(), R.layout.row_site_local, itemsLocal);
                                    tabLocal.sitesLocal.setAdapter(adapterLocal);

                                    OptionDialog.dismiss();

                                }

                            }
                        });

                        btnAddAfter.setLayoutParams(
                                new FrameLayout.LayoutParams(400, LinearLayout.LayoutParams.WRAP_CONTENT));
                        rlayout.addView(btnAddAfter);
                        listChannelAlreadyAdded.setLayoutParams(
                                new FrameLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                                        LinearLayout.LayoutParams.WRAP_CONTENT));
                        rlayout.addView(listChannelAlreadyAdded);
                        layout.addView(rlayout);
                    }

                    final Button btnCancel = new Button(MainActivity.getAppContext());
                    btnCancel.setText("Cancel");
                    btnCancel.setLayoutParams(
                            new FrameLayout.LayoutParams(400, LinearLayout.LayoutParams.WRAP_CONTENT));

                    btnCancel.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            OptionDialog.dismiss();
                        }
                    });

                    layout.addView(btnCancel);
                    alertDialog.setView(layout); // uncomment this line
                    alertDialog.setTitle("Take the Channel");
                    OptionDialog = alertDialog.create();
                    OptionDialog.show();
                }

            });

        }

    });

    return convertView;
}

From source file:com.cmput301w15t15.travelclaimsapp.activitys.EditClaimActivity.java

/**
 * Function that is called when you press the add tag
 * /*  ww  w .  j a va 2  s .c om*/
 * Creates a alert dialog that gives the user the option 
 * of adding a previously added tag or entering a new tag name
 * 
 * @param view
 */
public void addTagButton(View view) {
    final EditText enterTag = new EditText(this);
    final Spinner tagSpinner = new Spinner(this);
    //Linear layout that holds enterTag and tagSpinner views
    LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.VERTICAL);
    tagSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View arg1, int position, long id) {
            enterTag.setText(parent.getItemAtPosition(position).toString());
        }

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

    enterTag.setHint("Enter tag");
    AlertDialog.Builder alert = new AlertDialog.Builder(this);

    //get all the tags currently added to claims in application claimlist
    ArrayList<Tag> tags = ClaimListController.getTagList();
    String t[] = new String[tags.size()];
    for (int i = 0; i < tags.size(); i++) {
        t[i] = tags.get(i).getName();
    }
    //create a arrayadaptor for displaying the tagSpinner view, and set it
    ArrayAdapter<String> tagA = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, t);
    tagSpinner.setAdapter(tagA);
    //add views to linear layout and set the Linear layout view as the alert dialog view 
    ll.addView(tagSpinner);
    ll.addView(enterTag);
    alert.setView(ll);

    alert.setPositiveButton("Add", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            Tag tag = new Tag(enterTag.getText().toString());
            if (theClaim.getTagList().getTag(enterTag.getText().toString()) != null) {
                return;
            }
            ClaimListController.addTag(theClaim, tag);
            tagAdaptor.notifyDataSetChanged();
        }
    });
    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.cancel();
        }
    });

    alert.show();
}

From source file:br.com.carlosrafaelgn.fplay.ActivityBrowserRadio.java

@Override
public void onClick(View view) {
    if (view == btnGoBack) {
        if (isAtFavorites) {
            isAtFavorites = false;/* w ww.  j  a v a 2  s . c o m*/
            doSearch();
        } else {
            finish(0, view, true);
        }
    } else if (view == btnFavorite) {
        isAtFavorites = true;
        radioStationList.cancel();
        radioStationList.fetchFavorites(getApplication());
        updateButtons();
    } else if (view == btnSearch) {
        final Context ctx = getHostActivity();
        final LinearLayout l = (LinearLayout) UI.createDialogView(ctx, null);

        LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        chkGenre = new RadioButton(ctx);
        chkGenre.setText(R.string.genre);
        chkGenre.setChecked(Player.lastRadioSearchWasByGenre);
        chkGenre.setOnClickListener(this);
        chkGenre.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._DLGsp);
        chkGenre.setLayoutParams(p);

        p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        p.topMargin = UI._DLGsppad;
        btnGenre = new Spinner(ctx);
        btnGenre.setContentDescription(ctx.getText(R.string.genre));
        btnGenre.setLayoutParams(p);

        p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        p.topMargin = UI._DLGsppad << 1;
        chkTerm = new RadioButton(ctx);
        chkTerm.setText(R.string.search_term);
        chkTerm.setChecked(!Player.lastRadioSearchWasByGenre);
        chkTerm.setOnClickListener(this);
        chkTerm.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._DLGsp);
        chkTerm.setLayoutParams(p);

        p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        p.topMargin = UI._DLGsppad;
        txtTerm = new EditText(ctx);
        txtTerm.setContentDescription(ctx.getText(R.string.search_term));
        txtTerm.setText(Player.radioSearchTerm == null ? "" : Player.radioSearchTerm);
        txtTerm.setOnClickListener(this);
        txtTerm.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._DLGsp);
        txtTerm.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
        txtTerm.setSingleLine();
        txtTerm.setLayoutParams(p);

        p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        p.topMargin = UI._DLGsppad;
        p.bottomMargin = UI._DLGsppad;
        final TextView lbl = new TextView(ctx);
        lbl.setAutoLinkMask(0);
        lbl.setLinksClickable(true);
        //http://developer.android.com/design/style/color.html
        lbl.setLinkTextColor(new BgColorStateList(UI.isAndroidThemeLight() ? 0xff0099cc : 0xff33b5e5));
        lbl.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._14sp);
        lbl.setGravity(Gravity.CENTER_HORIZONTAL);
        lbl.setText(SafeURLSpan.parseSafeHtml(getText(R.string.by_dir_xiph_org)));
        lbl.setMovementMethod(LinkMovementMethod.getInstance());
        lbl.setLayoutParams(p);

        l.addView(chkGenre);
        l.addView(btnGenre);
        l.addView(chkTerm);
        l.addView(txtTerm);
        l.addView(lbl);

        btnGenre.setAdapter(this);
        btnGenre.setSelection(getValidGenre(Player.radioLastGenre));
        defaultTextColors = txtTerm.getTextColors();

        UI.prepareDialogAndShow((new AlertDialog.Builder(ctx)).setTitle(getText(R.string.search)).setView(l)
                .setPositiveButton(R.string.search, this).setNegativeButton(R.string.cancel, this)
                .setOnCancelListener(this).create());
    } else if (view == btnGoBackToPlayer) {
        finish(-1, view, false);
    } else if (view == btnAdd) {
        addPlaySelectedItem(false);
    } else if (view == btnPlay) {
        addPlaySelectedItem(true);
    } else if (view == chkGenre || view == btnGenre) {
        chkGenre.setChecked(true);
        chkTerm.setChecked(false);
    } else if (view == chkTerm || view == txtTerm) {
        chkGenre.setChecked(false);
        chkTerm.setChecked(true);
    } else if (view == list) {
        if (!isAtFavorites && !loading && (radioStationList == null || radioStationList.getCount() == 0))
            onClick(btnFavorite);
    }
}

From source file:com.mifos.mifosxdroid.online.generatecollectionsheet.GenerateCollectionSheetFragment.java

private void inflateCollectionTable(CollectionSheetResponse collectionSheetResponse) {
    //Clear old views in case they are present.
    if (tableProductive.getChildCount() > 0) {
        tableProductive.removeAllViews();
    }/*from  w  w w  .  j  ava2 s  .c o  m*/

    //A List to be used to inflate Attendance Spinners
    ArrayList<String> attendanceTypes = new ArrayList<>();
    attendanceTypeOptions.clear();
    attendanceTypeOptions = presenter.filterAttendanceTypes(collectionSheetResponse.getAttendanceTypeOptions(),
            attendanceTypes);

    additionalPaymentTypeMap.clear();
    additionalPaymentTypeMap = presenter.filterPaymentTypes(collectionSheetResponse.getPaymentTypeOptions(),
            paymentTypes);

    //Add the heading Row
    TableRow headingRow = new TableRow(getContext());
    TableRow.LayoutParams headingRowParams = new TableRow.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    headingRowParams.gravity = Gravity.CENTER;
    headingRowParams.setMargins(0, 0, 0, 10);
    headingRow.setLayoutParams(headingRowParams);

    TextView tvGroupName = new TextView(getContext());
    tvGroupName.setText(collectionSheetResponse.getGroups().get(0).getGroupName());
    tvGroupName.setTypeface(tvGroupName.getTypeface(), Typeface.BOLD);
    tvGroupName.setGravity(Gravity.CENTER);
    headingRow.addView(tvGroupName);

    for (LoanProducts loanProduct : collectionSheetResponse.getLoanProducts()) {
        TextView tvProduct = new TextView(getContext());
        tvProduct.setText(getString(R.string.collection_loan_product, loanProduct.getName()));
        tvProduct.setTypeface(tvProduct.getTypeface(), Typeface.BOLD);
        tvProduct.setGravity(Gravity.CENTER);
        headingRow.addView(tvProduct);
    }

    for (SavingsProduct savingsProduct : collectionSheetResponse.getSavingsProducts()) {
        TextView tvSavingProduct = new TextView(getContext());
        tvSavingProduct.setText(getString(R.string.collection_saving_product, savingsProduct.getName()));
        tvSavingProduct.setTypeface(tvSavingProduct.getTypeface(), Typeface.BOLD);
        tvSavingProduct.setGravity(Gravity.CENTER);
        headingRow.addView(tvSavingProduct);
    }

    TextView tvAttendance = new TextView(getContext());
    tvAttendance.setText(getString(R.string.attendance));
    tvAttendance.setGravity(Gravity.CENTER);
    tvAttendance.setTypeface(tvAttendance.getTypeface(), Typeface.BOLD);
    headingRow.addView(tvAttendance);

    tableProductive.addView(headingRow);

    for (ClientCollectionSheet clientCollectionSheet : collectionSheetResponse.getGroups().get(0)
            .getClients()) {
        //Insert rows
        TableRow row = new TableRow(getContext());
        TableRow.LayoutParams rowParams = new TableRow.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        rowParams.gravity = Gravity.CENTER;
        rowParams.setMargins(0, 0, 0, 10);
        row.setLayoutParams(rowParams);

        //Column 1: Client Name and Id
        TextView tvClientName = new TextView(getContext());
        tvClientName.setText(
                concatIdWithName(clientCollectionSheet.getClientName(), clientCollectionSheet.getClientId()));
        row.addView(tvClientName);

        //Subsequent columns: The Loan products
        for (LoanProducts loanProduct : collectionSheetResponse.getLoanProducts()) {
            //Since there may be several items in this column, create a container.
            LinearLayout productContainer = new LinearLayout(getContext());
            productContainer.setOrientation(LinearLayout.HORIZONTAL);

            //Iterate through all the loans in of this type and add in the container
            for (LoanCollectionSheet loan : clientCollectionSheet.getLoans()) {
                if (loanProduct.getName().equals(loan.getProductShortName())) {
                    //This loan should be shown in this column. So, add it in the container.
                    EditText editText = new EditText(getContext());
                    editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
                    editText.setText(String.format(Locale.getDefault(), "%f", 0.0));
                    //Set the loan id as the Tag of the EditText
                    // in format 'TYPE:ID' which
                    //will later be used as the identifier for this.
                    editText.setTag(TYPE_LOAN + ":" + loan.getLoanId());
                    productContainer.addView(editText);
                }
            }
            row.addView(productContainer);
        }

        //After Loans, show Savings columns
        for (SavingsProduct product : collectionSheetResponse.getSavingsProducts()) {
            //Since there may be several Savings items in this column, create a container.
            LinearLayout productContainer = new LinearLayout(getContext());
            productContainer.setOrientation(LinearLayout.HORIZONTAL);

            //Iterate through all the Savings in of this type and add in the container
            for (SavingsCollectionSheet saving : clientCollectionSheet.getSavings()) {
                if (saving.getProductId() == product.getId()) {
                    //Add the saving in the container
                    EditText editText = new EditText(getContext());
                    editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
                    editText.setText(String.format(Locale.getDefault(), "%f", 0.0));
                    //Set the Saving id as the Tag of the EditText
                    // in 'TYPE:ID' format which
                    //will later be used as the identifier for this.
                    editText.setTag(TYPE_SAVING + ":" + saving.getSavingsId());
                    productContainer.addView(editText);
                }
            }
            row.addView(productContainer);
        }

        Spinner spAttendance = new Spinner(getContext());
        //Set the clientId as its tag which will be used as identifier later.
        spAttendance.setTag(clientCollectionSheet.getClientId());
        setSpinner(spAttendance, attendanceTypes);
        row.addView(spAttendance);

        tableProductive.addView(row);
    }

    if (btnSubmitProductive.getVisibility() != View.VISIBLE) {
        //Show the button the first time sheet is loaded.
        btnSubmitProductive.setVisibility(View.VISIBLE);
        btnSubmitProductive.setOnClickListener(this);
    }

    //If this block has been executed, that means the CollectionSheet
    //which is already shown is for groups.
    btnSubmitProductive.setTag(TAG_TYPE_COLLECTION);

    if (tableAdditional.getVisibility() != View.VISIBLE) {
        tableAdditional.setVisibility(View.VISIBLE);
    }
    //Show Additional Views
    TableRow rowPayment = new TableRow(getContext());
    TextView tvLabelPayment = new TextView(getContext());
    tvLabelPayment.setText(getString(R.string.payment_type));
    rowPayment.addView(tvLabelPayment);
    Spinner spPayment = new Spinner(getContext());
    setSpinner(spPayment, paymentTypes);
    rowPayment.addView(spPayment);
    tableAdditional.addView(rowPayment);

    TableRow rowAccount = new TableRow(getContext());
    TextView tvLabelAccount = new TextView(getContext());
    tvLabelAccount.setText(getString(R.string.account_number));
    rowAccount.addView(tvLabelAccount);
    EditText etPayment = new EditText(getContext());
    rowAccount.addView(etPayment);
    tableAdditional.addView(rowAccount);

    TableRow rowCheck = new TableRow(getContext());
    TextView tvLabelCheck = new TextView(getContext());
    tvLabelCheck.setText(getString(R.string.cheque_number));
    rowCheck.addView(tvLabelCheck);
    EditText etCheck = new EditText(getContext());
    rowCheck.addView(etCheck);
    tableAdditional.addView(rowCheck);

    TableRow rowRouting = new TableRow(getContext());
    TextView tvLabelRouting = new TextView(getContext());
    tvLabelRouting.setText(getString(R.string.routing_code));
    rowRouting.addView(tvLabelRouting);
    EditText etRouting = new EditText(getContext());
    rowRouting.addView(etRouting);
    tableAdditional.addView(rowRouting);

    TableRow rowReceipt = new TableRow(getContext());
    TextView tvLabelReceipt = new TextView(getContext());
    tvLabelReceipt.setText(getString(R.string.receipt_number));
    rowReceipt.addView(tvLabelReceipt);
    EditText etReceipt = new EditText(getContext());
    rowReceipt.addView(etReceipt);
    tableAdditional.addView(rowReceipt);

    TableRow rowBank = new TableRow(getContext());
    TextView tvLabelBank = new TextView(getContext());
    tvLabelBank.setText(getString(R.string.bank_number));
    rowBank.addView(tvLabelBank);
    EditText etBank = new EditText(getContext());
    rowBank.addView(etBank);
    tableAdditional.addView(rowBank);
}

From source file:foam.jellyfish.StarwispBuilder.java

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

    try {//from   w w  w  .  ja v 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("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_NUMBER_FLAG_DECIMAL | 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);
            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) {
                    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,
                    android.R.layout.simple_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;
                }
            };

            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("nomadic")) {
            final int wid = arr.getInt(1);
            NomadicSurfaceView v = new NomadicSurfaceView(ctx, wid);
            v.setId(wid);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));

            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");

}