List of usage examples for android.widget ArrayAdapter ArrayAdapter
public ArrayAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List<T> objects)
From source file:com.example.awesomedogs.ui.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);//from w ww . j a va 2s.c o m ArrayAdapter<Dog> adapter = new ArrayAdapter<Dog>(this, R.layout.list_row, DoggyData.getDogs()) { @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = getLayoutInflater().inflate(R.layout.list_row, null, false); } Dog dog = getItem(position); TextView textView = (TextView) convertView; textView.setText(getItem(position).getName()); textView.setCompoundDrawablesWithIntrinsicBounds(dog.getIcon(), 0, 0, 0); return textView; } }; setListAdapter(adapter); getListView().setOnItemClickListener(this); }
From source file:com.manning.androidhacks.hack006.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getListView().setLayoutAnimation(/*from w ww. ja va 2 s. c o m*/ new LayoutAnimationController(AnimationUtils.loadAnimation(this, R.anim.list_animation), 0.5f)); setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Countries.COUNTRIES)); }
From source file:asu.edu.msse.gpeddabu.moviedescriptions.AddMovie.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add_movie); spinner = (Spinner) findViewById(R.id.genreET); getGenreList();/* w w w . j av a 2 s. c om*/ // Create an ArrayAdapter using the string array and a default spinner layout adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, genreArr); // Specify the layout to use when the list of choices appears adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner spinner.setAdapter(adapter); final EditText title = (EditText) findViewById(R.id.titleET); final Button addButton = (Button) findViewById(R.id.addButton); title.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { if (title.getText().toString().length() > 0) { addButton.setEnabled(true); } else { addButton.setEnabled(false); } } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (title.getText().toString().length() > 0) { addButton.setEnabled(true); } else { addButton.setEnabled(false); } } @Override public void afterTextChanged(Editable s) { if (title.getText().toString().length() > 0) { addButton.setEnabled(true); } else { addButton.setEnabled(false); } } }); }
From source file:com.aleiacampo.oristanobus.util.ViewUtil.java
public static void loadMostSearched(final AppCompatActivity appCompatActivity) { final ArrayList<Stop> stopsList = new ArrayList<>(); final ArrayList<String> stopsNameList = new ArrayList<>(); new AsyncTask<Void, Void, Void>() { @Override//from w ww.j ava 2 s . c om protected void onPreExecute() { super.onPreExecute(); if (!ConnectionsHandler.isNetworkPresent(appCompatActivity)) { this.cancel(true); stopsNameList.add("Connessione dati non presente"); ListView listView_searched = (ListView) appCompatActivity .findViewById(R.id.textView_mostSerched); ArrayAdapter<String> adapter = new ArrayAdapter<>(appCompatActivity.getApplicationContext(), R.layout.text_view, stopsNameList); listView_searched.setAdapter(adapter); } } @Override protected Void doInBackground(Void... params) { Stop stop; String url = "http://www.aleiacampo.com/stops.php?clicked=10"; WebServerHandler webServerHandler = new WebServerHandler(); String jsonStr = webServerHandler.getJSONData(url); try { JSONObject jsonObject = new JSONObject(jsonStr); JSONArray stopsJSON = jsonObject.getJSONArray("bus_stops"); for (int i = 0; i < stopsJSON.length(); i++) { JSONObject bus_stop = stopsJSON.getJSONObject(i); stop = new Stop(bus_stop.getInt("id_line"), bus_stop.getInt("id_stop"), bus_stop.getString("name_line"), bus_stop.getString("name_stop")); stopsList.add(stop); } } catch (Exception e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); for (Stop stop : stopsList) { stopsNameList.add("Linea " + stop.idLine + " - " + stop.nameStop); } ListView listView_searched = (ListView) appCompatActivity.findViewById(R.id.textView_mostSerched); ArrayAdapter<String> adapter = new ArrayAdapter<>(appCompatActivity.getApplicationContext(), R.layout.text_view, stopsNameList); listView_searched.setAdapter(adapter); listView_searched.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Bundle bundle = new Bundle(); bundle.putInt("id_stop", stopsList.get(position).idStop); bundle.putInt("id_line", stopsList.get(position).idLine); bundle.putString("name_line", stopsList.get(position).nameLine); bundle.putString("name_stop", stopsList.get(position).nameStop); FragmentManager fragmentManager = appCompatActivity.getSupportFragmentManager(); TimesFragment timesFragment = new TimesFragment(); timesFragment.setArguments(bundle); appCompatActivity.onBackPressed(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.home_frag, timesFragment, "Times"); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); } }); } }.execute(); }
From source file:com.springsource.greenhouse.events.EventDetailsActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.event_details); final ListView listView = (ListView) findViewById(R.id.event_details_menu); String[] menu_items = getResources().getStringArray(R.array.event_details_options_array); ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.menu_list_item, menu_items); listView.setAdapter(arrayAdapter);/*from w ww . j a v a2s . c o m*/ listView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = new Intent(); switch (position) { case 0: intent.setClass(view.getContext(), EventSessionsFilteredActivity.class); break; case 1: intent.setClass(view.getContext(), EventSessionsScheduleActivity.class); break; case 2: intent.setClass(view.getContext(), PostTweetActivity.class); break; case 3: intent.setClass(view.getContext(), EventTweetsActivity.class); break; default: break; } startActivity(intent); } }); }
From source file:MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); 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_checked, countries);//from w ww .j a v a 2s .c o m setListAdapter(countryAdapter); getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); getListView().setMultiChoiceModeListener(mMultiChoiceModeListener); getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ((ListView) parent).setItemChecked(position, true); } }); }
From source file:com.springsource.greenhouse.events.sessions.EventSessionDetailsActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.event_session_details); final ListView listView = (ListView) findViewById(R.id.event_session_details_menu); String[] menu_items = getResources().getStringArray(R.array.event_session_details_options_array); ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.menu_list_item, menu_items); listView.setAdapter(arrayAdapter);//from w w w. j a v a 2 s. com listView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { switch (position) { case 0: new UpdateFavoriteTask().execute(); break; case 1: startActivity(new Intent(view.getContext(), EventSessionRatingActivity.class)); break; case 2: startActivity(new Intent(view.getContext(), PostTweetActivity.class)); break; case 3: startActivity(new Intent(view.getContext(), EventSessionTweetsActivity.class)); break; default: break; } } }); }
From source file:edu.rit.csh.androidwebnews.ComposeActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle extras = getIntent().getExtras(); hc.getNewsGroups(); // used for list of newsgroups to look through if (extras != null) { if (extras.containsKey("SUBJECT")) { // coming from a reply subject = extras.getString("SUBJECT"); body = extras.getString("QUOTED_TEXT"); parentId = extras.getInt("PARENT"); }/*from w w w.j a va 2 s.co m*/ // for when a new post is done from a newsgroup newsgroup = extras.getString("NEWSGROUP"); } setContentView(R.layout.activity_compose); dialog = new InvalidApiKeyDialog(this); ArrayList<String> groupNames = new ArrayList<String>(); listAdapter = new ArrayAdapter<String>(this, R.layout.rowlayout, groupNames); spinner = (Spinner) findViewById(R.id.newsgroupSpinner); if (parentId <= 0) {// do not display the spinner if it is a reply to a post spinner.setAdapter(listAdapter); spinner.setSelection(listAdapter.getPosition(newsgroup)); } else { spinner.setVisibility(View.GONE); } subLine = (EditText) findViewById(R.id.subject_line); subLine.setText(subject); bodyText = (EditText) findViewById(R.id.post_body); bodyText.setText(body); setTitle("Compose"); }
From source file:com.aevi.simpleexample.SecureCommunicationsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_https_example); adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, consoleLines); ListView console = (ListView) findViewById(R.id.consoleView); console.setAdapter(adapter);/*from w ww .j a v a 2 s.c o m*/ setupSearchTextEnterListener(); progressBarVisible(false); }
From source file:com.springsource.greenhouse.twitter.TweetDetailsActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.tweet_details); final ListView listView = (ListView) findViewById(R.id.tweet_details_menu); String[] menu_items = getResources().getStringArray(R.array.tweet_details_options_array); ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.menu_list_item, menu_items); listView.setAdapter(arrayAdapter);//from w w w. j ava 2 s . c o m listView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { switch (position) { case 0: Intent replyIntent = new Intent(view.getContext(), PostTweetActivity.class); replyIntent.putExtra("reply", tweet.getFromUser()); startActivity(replyIntent); break; case 1: showRetweetDialog(); break; case 2: Intent quoteIntent = new Intent(view.getContext(), PostTweetActivity.class); String quote = new StringBuilder().append("\"@").append(tweet.getFromUser()).append(" ") .append(tweet.getText()).append("\"").toString(); quoteIntent.putExtra("quote", quote); startActivity(quoteIntent); break; default: break; } } }); }