Example usage for android.widget ArrayAdapter ArrayAdapter

List of usage examples for android.widget ArrayAdapter ArrayAdapter

Introduction

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

Prototype

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

Source Link

Document

Constructor

Usage

From source file:com.max2idea.android.limbo.main.LimboActivity.java

private void populateFloppy(String fileType) {
    // Add from History
    ArrayList<String> oldFDs = favDB.getFavURL(fileType);
    int length = 0;
    if (oldFDs == null || oldFDs.size() == 0) {
        length = 0;/* w  ww  . ja  va  2  s .  co m*/
    } else {
        length = oldFDs.size();
    }

    ArrayList<String> arraySpinner = new ArrayList<String>();
    arraySpinner.add("None");
    arraySpinner.add("Open");
    if (oldFDs != null) {
        Iterator i = oldFDs.iterator();
        while (i.hasNext()) {
            String file = (String) i.next();
            if (file != null) {
                arraySpinner.add(file);
            }
        }
    }

    if (fileType.equals("fda")) {
        fdaAdapter = new ArrayAdapter(this, R.layout.custom_spinner_item, arraySpinner);
        fdaAdapter.setDropDownViewResource(R.layout.custom_spinner_dropdown_item);
        this.mFDA.setAdapter(fdaAdapter);
        this.mFDA.invalidate();
    } else if (fileType.equals("fdb")) {
        fdbAdapter = new ArrayAdapter(this, R.layout.custom_spinner_item, arraySpinner);
        fdbAdapter.setDropDownViewResource(R.layout.custom_spinner_dropdown_item);
        this.mFDB.setAdapter(fdbAdapter);
        this.mFDB.invalidate();
    }
}

From source file:com.nttec.everychan.ui.presentation.BoardFragment.java

private void setNavigationCatalogBar() {
    if (presentationModel == null)
        return;//w  w w  .j  a  va 2s. c  o  m
    if (tabModel.pageModel.type == UrlPageModel.TYPE_BOARDPAGE) {
        View.OnClickListener navigationBarOnClickListener = new NavigationBarOnClickListener(this);
        for (int id : new int[] { R.id.board_navigation_previous, R.id.board_navigation_next,
                R.id.board_navigation_page }) {
            navigationBarView.findViewById(id).setOnClickListener(navigationBarOnClickListener);
        }
        ((TextView) navigationBarView.findViewById(R.id.board_navigation_page))
                .setText(String.valueOf(tabModel.pageModel.boardPage));
        if (tabModel.pageModel.boardPage == presentationModel.source.boardModel.firstPage) {
            navigationBarView.findViewById(R.id.board_navigation_previous).setVisibility(View.INVISIBLE);
        }
        if (tabModel.pageModel.boardPage == presentationModel.source.boardModel.lastPage) {
            navigationBarView.findViewById(R.id.board_navigation_next).setVisibility(View.INVISIBLE);
        }

    } else if (tabModel.pageModel.type == UrlPageModel.TYPE_CATALOGPAGE) {
        String[] catalogTypes = presentationModel.source.boardModel.catalogTypeDescriptions;
        if (catalogTypes == null)
            catalogTypes = new String[] { resources.getString(R.string.catalog_default) };
        catalogBarView.setAdapter(new ArrayAdapter<String>(activity,
                android.R.layout.simple_spinner_dropdown_item, catalogTypes));
        catalogBarView.setSelection(tabModel.pageModel.catalogType);
        catalogBarView.setOnItemSelectedListener(new CatalogOnSelectedListener(this));
    }
}

From source file:com.rfo.basic.Run.java

private void doDebugDialog() {

    int lineIndex = 0;
    String text = "";
    if (mInterpreter != null) {
        lineIndex = mInterpreter.ExecutingLineIndex;
        text = mInterpreter.ExecutingLineBuffer.text();
    }//from  ww  w. ja va2  s  . c o  m

    ArrayList<String> msg = new ArrayList<String>();

    if (!dbDialogProgram) {
        msg = mInterpreter.dbDoFunc();
        msg.add("Executable Line #:    " + Integer.toString(lineIndex + 1) + '\n' + chomp(text));
    }

    if (dbDialogScalars)
        msg.addAll(mInterpreter.dbDoScalars("  "));
    if (dbDialogArray)
        msg.addAll(mInterpreter.dbDoArray("  "));
    if (dbDialogList)
        msg.addAll(mInterpreter.dbDoList("  "));
    if (dbDialogStack)
        msg.addAll(mInterpreter.dbDoStack("  "));
    if (dbDialogBundle)
        msg.addAll(mInterpreter.dbDoBundle("  "));
    if (dbDialogWatch)
        msg.addAll(mInterpreter.dbDoWatch("  "));

    if (dbDialogProgram) {
        for (int i = 0; i < Basic.lines.size(); ++i) {
            msg.add(((i == lineIndex) ? " >>" : "   ") // mark current line
                    + (i + 1) + ": " // one-based line index
                    + chomp(Basic.lines.get(i).text())); // remove newline
        }
    }

    LayoutInflater inflater = getLayoutInflater();
    View dialogLayout = inflater.inflate(R.layout.debug_dialog_layout, null);

    ListView debugView = (ListView) dialogLayout.findViewById(R.id.debug_list);
    debugView.setAdapter(new ArrayAdapter<String>(Run.this, R.layout.debug_list_layout, msg));
    debugView.setVerticalScrollBarEnabled(true);
    if (dbDialogProgram) {
        debugView.setSelection(lineIndex);
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(Run.this).setCancelable(true)
            .setTitle(R.string.debug_name).setView(dialogLayout);

    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface arg0) {
            DebuggerHalt = true;
            WaitForDebugResume = false;
            releaseDebugLOCK();
        }
    });

    builder.setPositiveButton("Resume", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            WaitForDebugResume = false;
            releaseDebugLOCK();
        }
    });

    builder.setNeutralButton("Step", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            DebuggerStep = true;
            WaitForDebugResume = true;
            releaseDebugLOCK();
        }
    });

    builder.setNegativeButton("View Swap", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dbSwap = true;
            releaseDebugLOCK();
        }
    });

    dbDialog = builder.show();
    dbDialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT);
}

From source file:com.rfo.basic.Run.java

private void doDebugSwapDialog() {

    ArrayList<String> msg = new ArrayList<String>();
    msg.addAll(Arrays.asList("Program", "Scalars", "Array", "List", "Stack", "Bundle", "Watch"));
    final String[] names = { "View Program", "View Scalars", "View Array", "View List", "View Stack",
            "View Bundle", "View Watch", "View Console" };

    LayoutInflater inflater = getLayoutInflater();
    View dialogLayout = inflater.inflate(R.layout.debug_list_s_layout, null);

    ListView debugView = (ListView) dialogLayout.findViewById(R.id.debug_list_s);
    debugView.setAdapter(new ArrayAdapter<String>(Run.this, R.layout.simple_list_layout_1, msg));
    debugView.setVerticalScrollBarEnabled(true);
    debugView.setClickable(true);/*from ww  w.  j a va 2  s.co  m*/

    debugView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            DialogSelector(position);
            boolean dosel = (dbDialogArray && WatchedArray == null) || (dbDialogList && WatchedList == -1)
                    || (dbDialogStack && WatchedStack == -1) || (dbDialogBundle && WatchedBundle == -1);
            if (dosel) {
                // if the element has not been defined ask if user wishes to do so.
                // or at least this is where it will go.
                // for now, default to view program.
                DialogSelector(0);
                position = 0;
            }
            String name = (position < names.length) ? names[position] : "";
            Toaster(name).show();
        }
    });

    AlertDialog.Builder builder = new AlertDialog.Builder(Run.this).setCancelable(true).setTitle("Select View:")
            .setView(dialogLayout);

    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface arg0) {
            WaitForSwap = false;
        }
    });

    builder.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            WaitForSwap = false;
            dbSwap = false;
        }
    });

    /*  // leave out until the element selector is done.
          builder.setNeutralButton("Choose Element",
             new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog,int which) {
       WaitForSelect = true;
    }
             });
    */
    dbSwapDialog = builder.show();
    dbSwapDialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT);
}

From source file:com.guardtrax.ui.screens.HomeScreen.java

private void initializeSpinnerControl() {
    List<String> SpinnerArray = Utility.getincidentcodeList(HomeScreen.this);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.spinner_text, SpinnerArray);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    spinner.setAdapter(adapter);/*from  w w w  .java2 s  .c o m*/

    //default the spinner to the start shift code set to position 0
    spinner.setSelection(0);

    // Register a callback to be invoked when an item in this AdapterView has been selected
    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            selectedCode = Utility.getkeyCode(HomeScreen.this, position);

            //if traffic violation module then set flag
            if (selectedCode.equalsIgnoreCase(GTConstants.trafficCode))
                trafficIncident = true;
            //else
            //trafficIncident = false;

            /*
            //start the send code timer, except the first item (start shift) and the default item (usually All Clear)
            if( spinner.getSelectedItemPosition() != 0 && spinner.getSelectedItemPosition() != 2)
            {
               incidentcodeSent = false;
               initializenoclickTimer();
            }
            */
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            Toast.makeText(HomeScreen.this, "Please select an Item ", Toast.LENGTH_LONG).show();
        }

    });
}

From source file:com.nttec.everychan.ui.presentation.BoardFragment.java

private void showThreadPreviewDialog(final int position) {
    final List<PresentationItemModel> items = new ArrayList<>();
    final int bgShadowResource = ThemeUtils.getThemeResId(activity.getTheme(), R.attr.dialogBackgroundShadow);
    final int bgColor = ThemeUtils.getThemeColor(activity.getTheme(), R.attr.activityRootBackground,
            Color.BLACK);/*from   w  w  w .j a v a 2s.co m*/
    final View tmpV = new View(activity);
    final Dialog tmpDlg = new Dialog(activity);
    tmpDlg.getWindow().setBackgroundDrawableResource(bgShadowResource);
    tmpDlg.requestWindowFeature(Window.FEATURE_NO_TITLE);
    tmpDlg.setCanceledOnTouchOutside(true);
    tmpDlg.setContentView(tmpV);
    tmpDlg.show();
    Runnable next = new Runnable() {
        @Override
        public void run() {
            final int dlgWidth = tmpV.getWidth();
            tmpDlg.hide();
            tmpDlg.cancel();
            final Dialog dialog = new Dialog(activity);

            if (presentationModel.source != null && presentationModel.source.threads != null
                    && presentationModel.source.threads.length > position
                    && presentationModel.source.threads[position].posts != null
                    && presentationModel.source.threads[position].posts.length > 0) {

                final String threadNumber = presentationModel.source.threads[position].posts[0].number;

                ClickableURLSpan.URLSpanClickListener spanClickListener = new ClickableURLSpan.URLSpanClickListener() {
                    @Override
                    public void onClick(View v, ClickableURLSpan span, String url, String referer) {
                        if (url.startsWith("#")) {
                            try {
                                UrlPageModel threadPageModel = new UrlPageModel();
                                threadPageModel.chanName = chan.getChanName();
                                threadPageModel.type = UrlPageModel.TYPE_THREADPAGE;
                                threadPageModel.boardName = tabModel.pageModel.boardName;
                                threadPageModel.threadNumber = threadNumber;
                                url = chan.buildUrl(threadPageModel) + url;
                                dialog.dismiss();
                                UrlHandler.open(chan.fixRelativeUrl(url), activity);
                            } catch (Exception e) {
                                Logger.e(TAG, e);
                            }
                        } else {
                            dialog.dismiss();
                            UrlHandler.open(chan.fixRelativeUrl(url), activity);
                        }
                    }
                };

                AndroidDateFormat.initPattern();
                String datePattern = AndroidDateFormat.getPattern();
                DateFormat dateFormat = datePattern == null
                        ? DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT)
                        : new SimpleDateFormat(datePattern, Locale.US);
                dateFormat.setTimeZone(settings.isLocalTime() ? TimeZone.getDefault()
                        : TimeZone.getTimeZone(presentationModel.source.boardModel.timeZoneId));

                int postsCount = presentationModel.source.threads[position].postsCount;
                boolean showIndex = presentationModel.source.threads[position].posts.length <= postsCount;
                int curPostIndex = postsCount - presentationModel.source.threads[position].posts.length + 1;

                boolean openSpoilers = settings.openSpoilers();

                for (int i = 0; i < presentationModel.source.threads[position].posts.length; ++i) {
                    PresentationItemModel model = new PresentationItemModel(
                            presentationModel.source.threads[position].posts[i], chan.getChanName(),
                            presentationModel.source.pageModel.boardName,
                            presentationModel.source.pageModel.threadNumber, dateFormat, spanClickListener,
                            imageGetter, ThemeUtils.ThemeColors.getInstance(activity.getTheme()), openSpoilers,
                            floatingModels, null);
                    model.buildSpannedHeader(showIndex ? (i == 0 ? 1 : ++curPostIndex) : -1,
                            presentationModel.source.boardModel.bumpLimit,
                            presentationModel.source.boardModel.defaultUserName, null, false);
                    items.add(model);
                }
            } else {
                items.add(presentationModel.presentationList.get(position));
            }
            ListView dlgList = new ListView(activity);
            dlgList.setAdapter(new ArrayAdapter<PresentationItemModel>(activity, 0, items) {
                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                    View view = adapter.getView(position, convertView, parent, dlgWidth, getItem(position));
                    view.setBackgroundColor(bgColor);
                    return view;
                }
            });
            dialog.getWindow().setBackgroundDrawableResource(bgShadowResource);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCanceledOnTouchOutside(true);
            dialog.setContentView(dlgList);
            dialog.show();
            dialogs.add(dialog);
        }
    };
    if (tmpV.getWidth() != 0) {
        next.run();
    } else {
        AppearanceUtils.callWhenLoaded(tmpDlg.getWindow().getDecorView(), next);
    }
}

From source file:com.nttec.everychan.ui.presentation.BoardFragment.java

private void openReferencesList(final String from) {
    final List<Integer> positions = new ArrayList<>();
    int position = -1;
    for (int i = 0; i < presentationModel.presentationList.size(); ++i) {
        if (presentationModel.presentationList.get(i).sourceModel.number.equals(from)) {
            position = i;/*from ww  w .  j  a va2 s.c  om*/
            break;
        }
    }
    if (position != -1) {
        Spanned referencesString = presentationModel.presentationList.get(position).referencesString;
        if (referencesString == null) {
            Logger.e(TAG, "null referencesString");
            return;
        }
        ClickableURLSpan[] spans = referencesString.getSpans(0, referencesString.length(),
                ClickableURLSpan.class);
        for (ClickableURLSpan span : spans) {
            String url = span.getURL();
            try {
                //url    , .. ???  PresentationItemModel ( )
                UrlPageModel model = UrlHandler.getPageModel(url);
                for (; position < presentationModel.presentationList.size(); ++position) {
                    if (presentationModel.presentationList.get(position).sourceModel.number
                            .equals(model.postNumber)) {
                        break;
                    }
                }
                if (position < presentationModel.presentationList.size())
                    positions.add(position);
            } catch (Exception e) {
                Logger.e(TAG, e);
            }
        }
    }

    if (positions.size() == 0) {
        Logger.e(TAG, "no references");
        return;
    }

    final int bgShadowResource = ThemeUtils.getThemeResId(activity.getTheme(), R.attr.dialogBackgroundShadow);
    final int bgColor = ThemeUtils.getThemeColor(activity.getTheme(), R.attr.activityRootBackground,
            Color.BLACK);
    final View tmpV = new View(activity);
    final Dialog tmpDlg = new Dialog(activity);
    tmpDlg.getWindow().setBackgroundDrawableResource(bgShadowResource);
    tmpDlg.requestWindowFeature(Window.FEATURE_NO_TITLE);
    tmpDlg.setCanceledOnTouchOutside(true);
    tmpDlg.setContentView(tmpV);
    tmpDlg.show();
    Runnable next = new Runnable() {
        @Override
        public void run() {
            final int dlgWidth = tmpV.getWidth();
            tmpDlg.hide();
            tmpDlg.cancel();

            ListView dlgList = new ListView(activity);
            dlgList.setAdapter(new ArrayAdapter<Integer>(activity, 0, positions) {
                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                    try {
                        int adapterPositon = getItem(position);
                        View view = adapter.getView(adapterPositon, convertView, parent, dlgWidth,
                                adapter.getItem(adapterPositon), from);
                        view.setBackgroundColor(bgColor);
                        return view;
                    } catch (Exception e) {
                        Logger.e(TAG, e);
                        Toast.makeText(activity, R.string.error_unknown, Toast.LENGTH_LONG).show();
                        return new View(activity);
                    }
                }
            });

            Dialog dialog = new Dialog(activity);
            dialog.getWindow().setBackgroundDrawableResource(bgShadowResource);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCanceledOnTouchOutside(true);
            dialog.setContentView(dlgList);
            dialog.show();
            dialogs.add(dialog);
        }
    };
    if (tmpV.getWidth() != 0) {
        next.run();
    } else {
        AppearanceUtils.callWhenLoaded(tmpDlg.getWindow().getDecorView(), next);
    }
}