List of usage examples for android.widget ArrayAdapter ArrayAdapter
public ArrayAdapter(@NonNull Context context, @LayoutRes int resource, @IdRes int textViewResourceId, @NonNull List<T> objects)
From source file:net.noviden.android.shoutout.MainScreen.java
/** * refresh posts//from www . jav a 2s.c o m */ private void refreshPosts() { getPosts(); if (mStringPostsArray != null) { ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.rowlayout, R.id.label, mStringPostsArray); setListAdapter(adapter); } }
From source file:com.example.android.test.app.DemoActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);/*from w w w. j av a 2s . co m*/ mDisplay = (TextView) findViewById(R.id.display); context = getApplicationContext(); // Check device for Play Services APK. If check succeeds, proceed with GCM registration. if (checkPlayServices()) { gcm = GoogleCloudMessaging.getInstance(this); regid = getRegistrationId(context); if (regid.isEmpty()) { registerInBackground(); } } else { Log.i(TAG, "No valid Google Play Services APK found."); } List<Person> persons = Person.listAll(Person.class); ArrayList<String> notifications = new ArrayList<>(); // Copied for (int i = persons.size() - 1; i >= 0; --i) { notifications.add(persons.get(i).name + " detected on " + persons.get(i).time); } /*String [] notificationArray = { "This ", "is", "a", "Dynamic", "List", "to", "display", "notifications", "for", "the", " Application" }; List<String> notifications= new ArrayList<String>( Arrays.asList(notificationArray));*/ mNotificationAdapter = new ArrayAdapter<String>(this, R.layout.list_item_notifications, R.id.list_item_notifications_textview, notifications); ListView listView = (ListView) findViewById(R.id.listview_notifications); listView.setAdapter(mNotificationAdapter); }
From source file:itesm.mx.golpedecalor.SelectGroupActivity.java
@Override protected void onResume() { try {// ww w .java 2s . c o m dbo.open(); } catch (SQLException ex) { Log.e("", ex.toString()); } grupos = new ArrayList(dbo.getAllGroups()); nombres = new ArrayList<>(); for (Grupo g : grupos) { nombres.add(g.getNombre()); } adapter = new ArrayAdapter<String>(this, R.layout.activity_row, R.id.rowTV, nombres); miembrosLV.setAdapter(adapter); registerForContextMenu(miembrosLV); registerForContextMenu(miembrosLV); super.onResume(); }
From source file:dk.larsbak.sunshine.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Create some dummy data for the ListView. Here's a sample weekly forecast String[] data = { "Mon 6/23- Sunny - 31/17", "Tue 6/24 - Foggy - 21/8", "Wed 6/25 - Cloudy - 22/17", "Thurs 6/26 - Rainy - 18/11", "Fri 6/27 - Foggy - 21/10", "Sat 6/28 - TRAPPED IN WEATHERSTATION - 23/18", "Sun 6/29 - Sunny - 20/7" }; List<String> weekForecast = new ArrayList<>(Arrays.asList(data)); // Now that we have some dummy forecast data, create an ArrayAdapter. // The ArrayAdapter will take data from a source (like our dummy forecast) and // use it to populate the ListView it's attached to. mForecastAdapter = new ArrayAdapter<>(getActivity(), // The current context (this activity) R.layout.list_item_forecast, // The name of the layout ID. R.id.list_item_forecast_textview, // The ID of the textview to populate. weekForecast);//from w ww . java 2 s .com View rootView = inflater.inflate(R.layout.fragment_forecast, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast); listView.setAdapter(mForecastAdapter); // Set listener for onclick listView.setOnItemClickListener(onForecastClickListener); return rootView; }
From source file:com.example.polytech.orientatewatch.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The ArrayAdapter will take data from a source and // use it to populate the ListView it's attached to. mForecastAdapter = new ArrayAdapter<String>(getActivity(), // The current context (this activity) R.layout.list_item_forecast, // The name of the layout ID. R.id.list_item_forecast_textview, // The ID of the textview to populate. new ArrayList<String>()); mForecastAdapterDetails = new ArrayAdapter<String>(getActivity(), // The current context (this activity) R.layout.list_item_forecast, // The name of the layout ID. R.id.list_item_forecast_textview, // The ID of the textview to populate. new ArrayList<String>()); View rootView = inflater.inflate(R.layout.fragment_main, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast); listView.setAdapter(mForecastAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override/*from w w w.ja v a2 s . c o m*/ public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmpIcon.compress(Bitmap.CompressFormat.PNG, 100, stream); final byte[] byteArray = stream.toByteArray(); String forecast = mForecastAdapterDetails.getItem(position); Intent intent = new Intent(getActivity(), DetailActivity.class) .putExtra(Intent.EXTRA_TEXT, forecast).putExtra("icon", byteArray); startActivity(intent); } }); return rootView; }
From source file:io.v.android.apps.syncslides.NavigationDrawerFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mDrawerListView = (ListView) inflater.inflate(R.layout.fragment_navigation_drawer, container, false); mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override//from w w w.j ava 2 s . co m public void onItemClick(AdapterView<?> parent, View view, int position, long id) { selectItem(position); } }); mDrawerListView.setAdapter(new ArrayAdapter<String>(getActionBar().getThemedContext(), android.R.layout.simple_list_item_activated_2, android.R.id.text1, new String[] { mUserName }) { @Override public View getView(int position, View convertView, ViewGroup parent) { View view = super.getView(position, convertView, parent); ((TextView) view.findViewById(android.R.id.text1)).setText(mUserName); ((TextView) view.findViewById(android.R.id.text2)).setText(mUserEmail); return view; } }); mDrawerListView.setItemChecked(mCurrentSelectedPosition, true); return mDrawerListView; }
From source file:com.touchtechpayments.developer.sunshine.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { String[] data = { "Loading weather data for:", "Dublin, Ireland" }; List<String> weekForecast = new ArrayList<String>(Arrays.asList(data)); // Now that we have some dummy forecast data, create an ArrayAdapter. // The ArrayAdapter will take data from a source (like our dummy forecast) and // use it to populate the ListView it's attached to. mForecastAdapter = new ArrayAdapter<String>(getActivity(), // The current context (this activity) R.layout.list_item_forecast, // The name of the layout ID. R.id.list_item_forecast_textview, // The ID of the textview to populate. weekForecast);//from w w w . j av a2s .co m View rootView = inflater.inflate(R.layout.fragment_main, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast); listView.setAdapter(mForecastAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { // The parameter "position" refers to the position of the list item in mForecastAdapter // that was clicked @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { //TODO: Replace the Toast with an explicit intent to launch DetailActivity //getItem() returns the object @ position - in our case it's a string String forecast = (String) mForecastAdapter.getItem(position); //Toast.makeText(getActivity(), forecast, Toast.LENGTH_LONG).show(); Log.v("Toast string = ", forecast); Intent detailIntent = new Intent(getActivity(), DetailActivity.class).putExtra("test", forecast); startActivity(detailIntent); } }); return rootView; }
From source file:com.coinblesk.client.backup.BackupRestoreDialogFragment.java
private void initBackupFilesList() { File backupDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); File[] files = backupDir.listFiles(new FilenameFilter() { @Override/*from w w w. j a va 2 s .c o m*/ public boolean accept(File dir, String filename) { return filename.startsWith(Constants.BACKUP_FILE_PREFIX); } }); List<File> backupFiles = new ArrayList<>(); if (files != null) { for (File f : files) { backupFiles.add(f); } } Collections.sort(backupFiles); ArrayAdapter<File> fileAdapter = new ArrayAdapter<>(getContext(), R.layout.simple_multiline_list_item, R.id.text1, backupFiles); backupFilesList.setAdapter(fileAdapter); }
From source file:net.idlesoft.android.apps.github.activities.DiffFilesList.java
@Override public void onCreate(final Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.diff_file_list); mPrefs = getSharedPreferences(Hubroid.PREFS_NAME, 0); mUsername = mPrefs.getString("username", ""); mPassword = mPrefs.getString("password", ""); mGapi.authenticate(mUsername, mPassword); ((ImageButton) findViewById(R.id.btn_search)).setOnClickListener(new OnClickListener() { public void onClick(final View v) { startActivity(new Intent(DiffFilesList.this, Search.class)); }/*from ww w . j av a 2 s . com*/ }); final Bundle extras = getIntent().getExtras(); if (extras != null) { mRepositoryName = extras.getString("repo_name"); mRepositoryOwner = extras.getString("repo_owner"); mType = extras.getString("type"); try { mJson = new JSONObject(extras.getString("json")); } catch (final JSONException e) { e.printStackTrace(); } try { final TextView title = (TextView) findViewById(R.id.tv_page_title); if (mType.equals("added")) { title.setText("Added Files"); } else if (mType.equals("removed")) { title.setText("Removed Files"); } else if (mType.equals("modified")) { title.setText("Changed Files"); } else { title.setText("Files"); } /* * Split JSONArray into a String array so we can populate the * list of files */ final String[] filenames = new String[mJson.getJSONArray(mType).length()]; for (int i = 0; i < filenames.length; i++) { if (mType.equals("modified")) { filenames[i] = mJson.getJSONArray("modified").getJSONObject(i).getString("filename"); } else { filenames[i] = mJson.getJSONArray(mType).getString(i); } if (filenames[i].lastIndexOf("/") > -1) { filenames[i] = filenames[i].substring(filenames[i].lastIndexOf("/") + 1); } } mAdapter = new ArrayAdapter<String>(DiffFilesList.this, android.R.layout.simple_list_item_1, android.R.id.text1, filenames); final ListView file_list = (ListView) findViewById(R.id.lv_diffFileList_list); file_list.setAdapter(mAdapter); file_list.setOnItemClickListener(mOnFileListItemClick); } catch (final JSONException e) { e.printStackTrace(); } } }
From source file:com.example.faisal.sunshine.app.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Create some dummy data for the ListView. Here's a sample weekly forecast final String[] data = { "Mon 6/23- Sunny - 31/17", "Tue 6/24 - Foggy - 21/8", "Wed 6/25 - Cloudy - 22/17", "Thurs 6/26 - Rainy - 18/11", "Fri 6/27 - Foggy - 21/10", "Sat 6/28 - TRAPPED IN WEATHERSTATION - 23/18", "Sun 6/29 - Sunny - 20/7" }; final List<String> weekForecast = new ArrayList<String>(Arrays.asList(data)); // Now that we have some dummy forecast data, create an ArrayAdapter. // The ArrayAdapter will take data from a source (like our dummy forecast) and // use it to populate the ListView it's attached to. mForecastAdapter = new ArrayAdapter<String>(getActivity(), // The current context (this activity) R.layout.list_item_forecast, // The name of the layout ID. R.id.list_item_forecast_textview, // The ID of the textview to populate. weekForecast);//from w ww .j av a 2 s. c om View rootView = inflater.inflate(R.layout.fragment_main, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView = (ListView) rootView.findViewById(R.id.list_view_forecast); listView.setAdapter(mForecastAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Toast toast = Toast.makeText(getActivity(), mForecastAdapter.getItem(position), Toast.LENGTH_SHORT); toast.show(); Intent detailIntent = new Intent(getActivity(), DetailActivity.class); detailIntent.putExtra(Intent.EXTRA_TEXT, mForecastAdapter.getItem(position)); startActivity(detailIntent); } }); return rootView; }