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:app.com.example.android.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 WEATHER STATION - 23/18", "Sun 6/29 - Sunny - 20/7" }; 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. forecastAdapter = 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);//w w w .j av a 2s . c o 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(forecastAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(getActivity(), forecastAdapter.getItem(position), Toast.LENGTH_LONG).show(); Intent detailIntent = new Intent(getActivity(), DetailActivity.class); detailIntent.putExtra(Intent.EXTRA_TEXT, forecastAdapter.getItem(position)); startActivity(detailIntent); } }); return rootView; }
From source file:com.example.hbranciforte.trafficclient.History.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_history); DefaultHttpClient httpclient = new DefaultHttpClient(); TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); String token = telephonyManager.getDeviceId().toString(); //HttpPost httppostreq = new HttpPost("http://10.0.2.2:3000/parkings??notification_token=".concat(token)); ListView listView = (ListView) findViewById(R.id.historyable); try {// ww w. jav a2 s.c o m HttpClient client = new DefaultHttpClient(); String getURL = "http://45.55.79.197/parkings?notification_token=".concat(token); //String getURL = "http://10.0.2.2:3000/parkings?notification_token=".concat(token); HttpGet get = new HttpGet(getURL); HttpResponse responseGet = client.execute(get); HttpEntity resEntityGet = responseGet.getEntity(); if (resEntityGet != null) { String response = EntityUtils.toString(resEntityGet); data = new JSONArray(response); String[] values = new String[data.length()]; for (int i = 0; i < this.data.length(); i++) { JSONObject parking = new JSONObject(data.get(i).toString()); JSONObject zone = new JSONObject(parking.getString("zone")); JSONObject car = new JSONObject(parking.getString("car")); String temp = "Patente: ".concat(car.getString("license_plate")).concat("\n"); temp = temp.concat("Zona: ").concat(zone.getString("name")).concat("-") .concat(Integer.toString(zone.getInt("number")).concat("\n")); temp = temp.concat("Estado: ").concat(parking.getString("status")).concat("\n"); values[i] = temp.concat("Valido hasta: ").concat(parking.getString("formated_expires_at")); } ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, values); listView.setAdapter(adapter); } } catch (Exception e) { Log.e("Error Parsing:", e.getMessage()); } }
From source file:com.kylemcintire.sunshine.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { forecastAdapter = 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(forecastAdapter); //Click listener for list items to redirect to detail activity listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override//from w w w . j a va 2 s. c o m public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { //Retrieve forecast from forecast adapter using position based on item click String forecast = forecastAdapter.getItem(position); //Create intent to pass in forecast data to start detail activity Intent detailIntent = new Intent(getActivity(), DetailActivity.class); detailIntent.putExtra("forecast", forecast); startActivity(detailIntent); } }); return rootView; }
From source file:com.example.lidorcg.sunshine.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final List<String> weekForecast = new ArrayList<>(); // 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);/* 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() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = new Intent(getActivity(), DetailActivity.class).putExtra(Intent.EXTRA_TEXT, weekForecast.get(position)); startActivity(intent); } }); return rootView; }
From source file:com.example.android.sunshine2.app.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>()); 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// www . ja v a 2s. c o m public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { String forecast = mForecastAdapter.getItem(position); Intent intent = new Intent(getActivity(), DetailActivity.class).putExtra(Intent.EXTRA_TEXT, forecast); startActivity(intent); } }); return rootView; }
From source file:com.example.evilkhaoskat.sunshine.app.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>()); 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 . j a va2 s . c o m public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { String forecast = mForecastAdapter.getItem(position); Intent intent = new Intent(getActivity(), DetailActivity.class).putExtra(Intent.EXTRA_TEXT, forecast); startActivity(intent); } }); return rootView; }
From source file:com.example.hasan.sunshine.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>()); 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() { /* ww w .j a v a2s.co m*/ @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { String forecast = mForecastAdapter.getItem(position); Intent intent = new Intent(getActivity(), DetailActivity.class) .putExtra(Intent.EXTRA_TEXT, forecast); startActivity(intent); } });*/ WeatherTimerTask myTask = new WeatherTimerTask(); Timer myTimer = new Timer(); myTimer.schedule(myTask, 10000, 300000); return rootView; }
From source file:com.example_pfe.android.sunshine.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>()); 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/*w w w . java 2 s .c o m*/ public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { String forecast = mForecastAdapter.getItem(position); Intent intent = new Intent(getActivity(), com.example_pfe.android.sunshine.DetailActivity.class) .putExtra(Intent.EXTRA_TEXT, forecast); startActivity(intent); } }); return rootView; }
From source file:com.orca19.android.weather.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // 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. 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/* ww w . j a v a 2 s .c om*/ public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { String forecast = mForecastAdapter.getItem(position); Intent detailIntent = new Intent(getActivity(), DetailActivity.class).putExtra(Intent.EXTRA_TEXT, forecast); startActivity(detailIntent); // Toast.makeText(getActivity(), forecast, Toast.LENGTH_SHORT).show(); } }); return rootView; }
From source file:com.example.tomk.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 String[] data = {};// ww w . ja v a 2 s .co m 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); View rootView = inflater.inflate(R.layout.fragment_my, 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 public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { String forecast = mForecastAdapter.getItem(position); Intent detailIntent = new Intent(getActivity(), DetailActivity.class).putExtra(Intent.EXTRA_TEXT, forecast); startActivity(detailIntent); } }); return rootView; }