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) 

Source Link

Document

Constructor

Usage

From source file:Main.java

public static void getRingtonesDialog(Activity activity, Collection<String> items, int selected,
        DialogInterface.OnClickListener itemClickListener, DialogInterface.OnClickListener okClickListener,
        final DialogInterface.OnClickListener cancelClickListener) {
    AlertDialog.Builder builderSingle = new AlertDialog.Builder(activity);
    builderSingle.setTitle("Select Ringtone");
    final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(activity,
            android.R.layout.select_dialog_singlechoice);
    arrayAdapter.addAll(items);/*from  w ww  . j  a  va 2s.com*/

    builderSingle.setNegativeButton(android.R.string.cancel, cancelClickListener);

    builderSingle.setPositiveButton(android.R.string.ok, okClickListener);

    builderSingle.setSingleChoiceItems(arrayAdapter, selected, itemClickListener);

    builderSingle.setCancelable(false);

    builderSingle.show();
}

From source file:com.ternup.caddisfly.widget.FormSpinner.java

public FormSpinner(Context context, String property, JSONObject options) {
    super(context, property);

    _options = options;/*from  w  ww  .ja  v a2s  .  co m*/

    _spinner = new Spinner(context, Spinner.MODE_DIALOG);
    //_spinner.setLayoutParams( FormActivity.defaultLayoutParams );

    String p;
    String name;

    _propertyMap = new HashMap<String, String>();
    _adapter = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item);
    _adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    _spinner.setAdapter(_adapter);
    _spinner.setSelection(0);

    try {
        if (options != null) {
            JSONArray propertyNames = options.names();
            for (int i = 0; i < options.length(); i++) {
                name = propertyNames.getString(i);
                p = options.getString(name);

                _adapter.add(p);
                _propertyMap.put(p, name);
            }
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);

    params1.bottomMargin = 15;
    params1.topMargin = 0;

    _spinner.setLayoutParams(params1);

    _layout.addView(_spinner);
}

From source file:io.v.positioning.BluetoothPositionActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bluetoothposition);
    Button scanButton = (Button) findViewById(R.id.button_scan);
    scanButton.setOnClickListener(new View.OnClickListener() {
        @Override/*from   w  w  w . j a va  2 s . c o m*/
        public void onClick(View v) {
            doDiscovery();
            v.setVisibility(View.GONE);
        }
    });
    mRecordedDevices = new ArrayAdapter<String>(this, R.layout.device_name);
    ListView recordedDevicesListView = (ListView) findViewById(R.id.recorded_devices);
    recordedDevicesListView.setAdapter(mRecordedDevices);
    this.registerReceiver(mReceiver, new IntentFilter(BluetoothDevice.ACTION_FOUND));
    this.registerReceiver(mReceiver, new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED));
    mBtAdapter = BluetoothAdapter.getDefaultAdapter();
}

From source file:org.deviceconnect.android.uiapp.fragment.profile.ExtraProfileFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_extra_service, container, false);
    view.setBackgroundColor(getResources().getColor(android.R.color.background_light));

    final String[] methods = { "GET", "POST", "PUT", "DELETE" };
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
            android.R.layout.simple_spinner_item);
    for (int i = 0; i < methods.length; i++) {
        adapter.add(methods[i]);/*from   w ww  .j  a  va2 s.  co m*/
    }
    Spinner spinner = (Spinner) view.findViewById(R.id.spinner);
    spinner.setAdapter(adapter);

    Button sendButton = (Button) view.findViewById(R.id.fragment_extra_send);
    sendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View view) {
            onClickSend(view);
        }
    });

    return view;
}

From source file:com.example.hellojni.HelloJni.java

/** Called when the activity is first created. */
@Override// ww w.j  ava 2s.c o  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    vk = new Videokit(this);
    vk.initialise();

    frame = Bitmap.createBitmap(192, 144, Config.RGB_565);

    /*
    image_view = new ImageView(this);
    image_view.setImageBitmap(frame);
    setContentView(image_view);
    */
    setContentView(R.layout.file_list);
    listView = (ListView) findViewById(R.id.file_list_view);
    listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
    listView.setAdapter(listAdapter);

    httpClient = AndroidHttpClient.newInstance("AirVideoAndroid");
}

From source file:com.pgmacdesign.lacunacompanion.fragments.MailFragment.java

private void Initialize() {
    // Populate the tags Spinner.
    tagsSpinnerAdapter = new ArrayAdapter<String>(getActivity().getApplicationContext(),
            android.R.layout.simple_spinner_item);
    tagsSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    tagSelector = (Spinner) getActivity().findViewById(R.id.mailFilter);

    tagsSpinnerAdapter.add("Select Tag");
    tagsSpinnerAdapter.add("Tutorial");
    tagsSpinnerAdapter.add("Correspondence");
    tagsSpinnerAdapter.add("Alerts");
    tagsSpinnerAdapter.add("Attacks");
    tagsSpinnerAdapter.add("Colonization");
    tagsSpinnerAdapter.add("Complaint");
    tagsSpinnerAdapter.add("Excavator");
    tagsSpinnerAdapter.add("Mission");
    tagsSpinnerAdapter.add("Parliament");
    tagsSpinnerAdapter.add("Probe");
    tagsSpinnerAdapter.add("Spies");
    tagsSpinnerAdapter.add("Trade");

    tagSelector.setAdapter(tagsSpinnerAdapter); //Force closing here due to null pointer error!!!!!!!!!!!!

    spinnerReset = System.currentTimeMillis();
    tagSelector.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            if (System.currentTimeMillis() - spinnerReset < 1000) {
                //Nothing!
            } else if (System.currentTimeMillis() - spinnerReset > 1000) {
                Spinner tagSpinner = (Spinner) getActivity().findViewById(R.id.mailFilter);
                String selectedTag = tagSpinner.getSelectedItem().toString();

                // Only refresh if a tag was actually selected.
                if (selectedTag != "Select Tag") {
                    // Just in case the server only accepts lowercase.
                    filterTag = selectedTag.toLowerCase();
                    pageNum = 0; // Reset the page number.

                    refreshMail();/*w  w  w .  j  ava 2  s.  c o m*/
                }
            }
        }

        public void onNothingSelected(AdapterView<?> arg0) {

        }
    });

    pageSelector = (Spinner) getActivity().findViewById(R.id.mailPage);
    spinnerReset = System.currentTimeMillis();
    pageSelector.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            if (System.currentTimeMillis() - spinnerReset < 1000) {
                //Nothing!
            } else if (System.currentTimeMillis() - spinnerReset > 1000) {
                pageNum = pos + 1;

                refreshMail();
            }
        }

        public void onNothingSelected(AdapterView<?> arg0) {

        }
    });

}

From source file:com.nttec.everychan.ui.ShareActivity.java

private void handleIntent(Intent intent) {
    ArrayAdapter<Pair<TabModel, SerializablePage>> adapter = new ArrayAdapter<Pair<TabModel, SerializablePage>>(
            this, 0) {
        private final int drawablePadding = (int) (getResources().getDisplayMetrics().density * 5 + 0.5f);

        @Override//  www. j  a  v  a 2 s . c om
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = convertView == null
                    ? getLayoutInflater().inflate(android.R.layout.simple_list_item_1, parent, false)
                    : convertView;
            TextView tv = (TextView) view.findViewById(android.R.id.text1);
            tv.setEllipsize(TextUtils.TruncateAt.END);
            tv.setSingleLine();
            tv.setText(getItem(position).getLeft().title);
            tv.setCompoundDrawablesWithIntrinsicBounds(MainApplication.getInstance()
                    .getChanModule(getItem(position).getLeft().pageModel.chanName).getChanFavicon(), null, null,
                    null);
            tv.setCompoundDrawablePadding(drawablePadding);
            return view;
        }
    };
    for (TabModel tab : MainApplication.getInstance().tabsState.tabsArray) {
        if (tab.type == TabModel.TYPE_NORMAL && tab.pageModel.type != UrlPageModel.TYPE_SEARCHPAGE) {
            SerializablePage page = MainApplication.getInstance().pagesCache.getSerializablePage(tab.hash);
            if (page != null) {
                adapter.add(Pair.of(tab, page));
            }
        }
    }
    if (adapter.getCount() == 0) {
        for (Database.HistoryEntry entity : MainApplication.getInstance().database.getHistory()) {
            try {
                TabModel tab = new TabModel();
                tab.title = entity.title;
                tab.type = TabModel.TYPE_NORMAL;
                tab.webUrl = entity.url;
                tab.pageModel = UrlHandler.getPageModel(entity.url);
                tab.hash = ChanModels.hashUrlPageModel(tab.pageModel);
                SerializablePage page = MainApplication.getInstance().pagesCache.getSerializablePage(tab.hash);
                if (page != null) {
                    adapter.add(Pair.of(tab, page));
                }
            } catch (Exception e) {
                Logger.e(TAG, e);
            }
        }
        if (adapter.getCount() == 0) {
            Toast.makeText(this, R.string.share_no_tabs, Toast.LENGTH_LONG).show();
            finish();
            return;
        }
    }
    if (PostingService.isNowPosting()) {
        Toast.makeText(this, R.string.posting_now_posting, Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    selectedFile = null;
    if (intent != null) {
        Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
        if (uri != null) {
            File file = UriFileUtils.getFile(this, uri);
            if (file != null) {
                selectedFile = file;
            }
        }
    }
    if (selectedFile == null) {
        Toast.makeText(this, R.string.postform_cannot_attach, Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    setListAdapter(adapter);
}

From source file:org.deviceconnect.android.uiapp.fragment.profile.NetworkServiceDiscoveryProfileFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    mLogger.entering(getClass().getName(), "onCreateView",
            new Object[] { inflater, container, savedInstanceState });
    final Context context = getActivity();

    FrameLayout lframe = new FrameLayout(context);

    ListView lv = new ListView(getActivity());
    lv.setId(android.R.id.list);//from  w  w  w .  j av a 2s  .c  o m
    lv.setDrawSelectorOnTop(false);
    lframe.addView(lv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    lframe.setBackgroundColor(getResources().getColor(android.R.color.background_light));

    mListView = (ListView) lframe.findViewById(android.R.id.list);
    mListView.setAdapter(new ArrayAdapter<SmartDevice>(getActivity(), android.R.layout.simple_list_item_1));

    (new ServiceDiscoveryTask()).execute();

    mLogger.exiting(getClass().getName(), "onCreateView", mListView);
    return lframe;
}

From source file:microsoft.aspnet.signalr.client.test.integration.android.MainActivity.java

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

    AndroidTestPlatformContext testPlatformContext = new AndroidTestPlatformContext(this);
    ApplicationContext.setTestPlatformContext(testPlatformContext);

    setContentView(R.layout.activity_main);

    mTestCaseList = (ListView) findViewById(R.id.testCaseList);
    TestCaseAdapter testCaseAdapter = new TestCaseAdapter(this, R.layout.row_list_test_case);
    mTestCaseList.setAdapter(testCaseAdapter);

    mTestGroupSpinner = (Spinner) findViewById(R.id.testGroupSpinner);

    ArrayAdapter<TestGroup> testGroupAdapter = new ArrayAdapter<TestGroup>(this,
            android.R.layout.simple_spinner_item);
    mTestGroupSpinner.setAdapter(testGroupAdapter);
    mTestGroupSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override//w  w w  .ja  v  a2s.c  om
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            selectTestGroup(pos);
        }

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

    refreshTestGroupsAndLog();
}

From source file:org.openremote.android.console.view.PanelSelectSpinnerView.java

public PanelSelectSpinnerView(Context context) {
    super(context);
    setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    arrayAdapter = new ArrayAdapter<String>(context, R.layout.simple_spinner_item_center);
    arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    setAdapter(arrayAdapter);//from ww w.  j av a  2s. co m
    String currentPanel = AppSettingsModel.getCurrentPanelIdentity(context);
    if (!TextUtils.isEmpty(currentPanel)) {
        arrayAdapter.add(currentPanel);
    } else {
        arrayAdapter.add(CHOOSE_PANEL);
    }

    setOntouchListener(context, this);
}