List of usage examples for android.widget ArrayAdapter ArrayAdapter
public ArrayAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List<T> objects)
From source file:MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); GridView gridView = new GridView(this); setContentView(gridView);//from ww w . j a v a2 s . c om String[] countries = new String[] { "China", "France", "Germany", "India", "Russia", "United Kingdom", "United States" }; ListAdapter countryAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, countries); gridView.setAdapter(countryAdapter); gridView.setNumColumns(2); gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String s = ((TextView) view).getText() + " " + position; Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show(); } }); }
From source file:MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ListView listView = (ListView) findViewById(R.id.list); List sensorList = new ArrayList<String>(); List<Sensor> sensors = ((SensorManager) getSystemService(Context.SENSOR_SERVICE)) .getSensorList(Sensor.TYPE_ALL); for (Sensor sensor : sensors) { sensorList.add(sensor.getName()); }//w w w . j av a 2 s . c o m ListAdapter sensorAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, sensorList); listView.setAdapter(sensorAdapter); }
From source file:MasterFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); String[] countries = new String[] { "China", "France", "Germany", "India", "Russia", "United Kingdom", "United States" }; ListAdapter countryAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, countries);// w w w . ja va 2 s . c o m setListAdapter(countryAdapter); getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE); getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (mOnMasterSelectedListener != null) { mOnMasterSelectedListener.onItemSelected(((TextView) view).getText().toString()); } } }); }
From source file:MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefresh); mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override/*w ww . j a va2 s.com*/ public void onRefresh() { refreshList(); } }); mListView = (ListView) findViewById(android.R.id.list); final String[] countries = new String[] { "China", "France", "Germany", "India", "Russia", "United Kingdom", "United States" }; mArrayList = new ArrayList<String>(Arrays.asList(countries)); ListAdapter countryAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mArrayList); mListView.setAdapter(countryAdapter); }
From source file:adamin.com.dragandswiperecyclerview.MainFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); final String[] items = getResources().getStringArray(R.array.main_items); final ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, items);//ww w .j a v a 2 s . c o m setListAdapter(adapter); }
From source file:MainActivity.java
private void refreshList() { mRefreshCount++;/*from www.ja va 2 s . c o m*/ mArrayList.add("Refresh: " + mRefreshCount); ListAdapter countryAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mArrayList); mListView.setAdapter(countryAdapter); mSwipeRefreshLayout.setRefreshing(false); }
From source file:com.starwood.anglerslong.LicenseAddActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle bundle = this.getIntent().getExtras(); setContentView(R.layout.license_add); Spinner s = (Spinner) findViewById(R.id.spinner); @SuppressWarnings("unchecked") ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.state_array)); s.setAdapter(adapter);/*from w w w .j av a 2 s.com*/ s.setOnItemSelectedListener(this); isPopulated = bundle.getBoolean("isPopulated"); isArrayEmpty = bundle.getBoolean("isArrayEmpty"); if (bundle.containsKey("isEdit")) isEdit = bundle.getBoolean("isEdit"); if (bundle.containsKey("currentItemID")) currentItemID = bundle.getInt("currentItemID"); getSupportActionBar().setTitle(bundle.getString("title")); // getSupportActionBar().setSubtitle(bundle.getString("subtitle")); if (isEdit) { try { JsonStorage jsonStorage = new JsonStorage(getApplicationContext()); String json = jsonStorage.readProfileJSON(); // Store the JSON into string JSONObject j = new JSONObject(json); JSONObject outer = j.getJSONObject("outermost"); // Outermost JSON JSONArray innerArray = outer.getJSONArray("license"); JSONObject inner = innerArray.getJSONObject(currentItemID); Spinner editSpinner = (Spinner) findViewById(R.id.spinner); editSpinner.setSelection(inner.getInt("state") + 1); // Set spinner EditText edit = (EditText) findViewById(R.id.license_name); edit.setText(inner.getString("name")); edit = (EditText) findViewById(R.id.license_number); edit.setText(inner.getString("number")); edit = (EditText) findViewById(R.id.license_type); edit.setText(inner.getString("type")); edit = (EditText) findViewById(R.id.license_issue_date); edit.setText(inner.getString("issue_date")); edit = (EditText) findViewById(R.id.license_expiration_date); edit.setText(inner.getString("exp_date")); edit = (EditText) findViewById(R.id.license_birthday); edit.setText(inner.getString("birthday")); edit = (EditText) findViewById(R.id.license_huntered); edit.setText(inner.getString("huntered")); } catch (JSONException | IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:aleajactatest.appiumcalculator.DummyListFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); final List<String> items = new ArrayList<String>(); for (int i = 0; i < 30; i++) items.add("Sloubi " + (i + 1)); final ArrayAdapter<String> la = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, items);// www. j a v a 2s . c om ListView lv = (ListView) getView().findViewById(R.id.dummyList); lv.setAdapter(la); }
From source file:com.apptentive.android.dev.InteractionsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.interactions); final AutoCompleteTextView eventName = (AutoCompleteTextView) findViewById(R.id.event_name); String[] events = getResources().getStringArray(R.array.events); ArrayAdapter<String> eventAdapter = new ArrayAdapter<String>(InteractionsActivity.this, android.R.layout.simple_dropdown_item_1line, events); eventName.setAdapter(eventAdapter);//from w ww . j av a2s .c o m eventName.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { eventName.showDropDown(); return false; } }); eventName.setText(null); }
From source file:fi.iki.murgo.irssinotifier.InitialSettingsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.initialsettings); preferences = new Preferences(this); if (LicenseHelper.isPlusVersion(this)) { TextView tv = (TextView) findViewById(R.id.textViewWelcomeHelp); tv.setText(getString(R.string.welcome_thanks_for_support) + " " + tv.getText()); }//from w ww . j a v a2s . com UserHelper fetcher = new UserHelper(); final Account[] accounts = fetcher.getAccounts(this); String[] accountNames = new String[accounts.length]; for (int i = 0; i < accounts.length; i++) { accountNames[i] = accounts[i].name; } ListView listView = (ListView) findViewById(R.id.accountsList); listView.setAdapter(new ArrayAdapter<String>(this, R.layout.accountlistitem, accountNames)); listView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { Account account = accounts[arg2]; preferences.setAccountName(account.name); preferences.setNotificationsEnabled(true); whatNext(0); } }); if (LicenseHelper.bothEditionsInstalled(this)) { MessageBox.Show(this, null, getString(R.string.both_versions_installed), null); } }