List of usage examples for android.widget ListView setAdapter
@Override public void setAdapter(ListAdapter adapter)
From source file:com.example.houcem.sunshine.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The CursorAdapter will take data from our cursor and populate the ListView. mForecastAdapter = new ForecastAdapter(getActivity(), null, 0); 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); // We'll call our MainActivity listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override//from w w w . j a v a 2 s . com public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { // CursorAdapter returns a cursor at the correct position for getItem(), or null // if it cannot seek to that position. Cursor cursor = (Cursor) adapterView.getItemAtPosition(position); if (cursor != null) { String locationSetting = com.example.houcem.sunshine.Utility .getPreferredLocation(getActivity()); Intent intent = new Intent(getActivity(), DetailActivity.class) .setData(WeatherContract.WeatherEntry.buildWeatherLocationWithDate(locationSetting, cursor.getLong(COL_WEATHER_DATE))); startActivity(intent); } } }); return rootView; }
From source file:com.example.hp.isun.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The CursorAdapter will take data from our cursor and populate the ListView. mForecastAdapter = new ForecastAdapter(getActivity(), null, 0); if (mForecastAdapter.getCount() == 0) { Toast.makeText(getActivity(), "Ures", Toast.LENGTH_LONG).show(); }// w w w . jav a 2 s . 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(mForecastAdapter); // We'll call our MainActivity listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { // CursorAdapter returns a cursor at the correct position for getItem(), or null // if it cannot seek to that position. Cursor cursor = (Cursor) adapterView.getItemAtPosition(position); if (cursor != null) { String locationSetting = Utility.getPreferredLocation(getActivity()); // Toast.makeText(getActivity(),locationSetting, Toast.LENGTH_LONG).show(); Intent intent = new Intent(getActivity(), DetailActivity.class) .setData(WeatherContract.WeatherEntry.buildWeatherLocationWithDate(locationSetting, cursor.getLong(COL_WEATHER_DATE))); startActivity(intent); } else { Toast.makeText(getActivity(), "Ures", Toast.LENGTH_LONG).show(); } } }); return rootView; }
From source file:bhav.sunshine.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The CursorAdapter will take data from our cursor and populate the ListView. mForecastAdapter = new ForecastAdapter(getActivity(), null, 0); SharedPreferences prefs = getActivity().getSharedPreferences("prefs", Context.MODE_PRIVATE); mLocation = prefs.getString(String.valueOf(R.string.pref_location_key), String.valueOf(R.string.pref_location_default)); 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 a 2 s. c o m public void onItemClick(AdapterView adapterView, View view, int position, long l) { // CursorAdapter returns a cursor at the correct position for getItem(), or null // if it cannot seek to that position. Cursor cursor = (Cursor) adapterView.getItemAtPosition(position); if (cursor != null) { String locationSetting = Utility.getPreferredLocation(getActivity()); Intent intent = new Intent(getActivity(), DetailActivity.class) .setData(WeatherContract.WeatherEntry.buildWeatherLocationWithDate(locationSetting, cursor.getLong(COL_WEATHER_DATE))); startActivity(intent); } } }); return rootView; }
From source file:com.example.asaf.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 ForecastAdapter(getActivity(), null, 0); 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/*from w w w. j a va 2s . com*/ public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { Cursor cursor = mForecastAdapter.getCursor(); if (cursor != null && cursor.moveToPosition(position)) { ((Callback) getActivity()).onItemSelected(cursor.getString(COL_WEATHER_DATE)); } } }); return rootView; }
From source file:br.pro.menotti.opus.pt.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); db = new SQLiteHelper(getApplicationContext()); String listStr[] = getResources().getStringArray(R.array.listString); ListView lv = (ListView) findViewById(android.R.id.list); lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listStr)); lv.setOnItemClickListener(new OnItemClickListener() { @Override//from w ww. j a va2 s . c o m public void onItemClick(AdapterView<?> parent, View view, int position, long id) { SQLiteHelper db; switch (position) { case 0: showBooks(); break; case 1: AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext()); builder.setTitle(R.string.display_search); final EditText input = new EditText(view.getContext()); builder.setView(input); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String search_key = input.getEditableText().toString().trim(); if (!search_key.equals("")) { showPoints(search_key); } } }); AlertDialog alertDialog = builder.create(); alertDialog.show(); break; case 2: db = new SQLiteHelper(getBaseContext()); db.openDataBase(); showFavorites(); db.close(); break; case 3: db = new SQLiteHelper(getBaseContext()); db.openDataBase(); BookPoint bp = db.getBookPoint(); DialogFragment newFragment = new DialogPoint(bp); newFragment.show(getSupportFragmentManager(), bp.toString()); db.close(); break; default: Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show(); } } }); try { db.createDataBase(); } catch (IOException ioe) { throw new Error("Unable to create database"); } try { db.openDataBase(); db.close(); } catch (SQLException sqle) { throw sqle; } }
From source file:com.fallahpoor.infocenter.fragments.GeneralFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); View view = inflater.inflate(R.layout.fragment_others, container, false); mHandler = new Handler(getActivity().getMainLooper(), this); mArrayAdapter = new CustomArrayAdapter(getActivity(), getListItems()); ListView listView = (ListView) view.findViewById(R.id.listView); listView.setAdapter(mArrayAdapter); return view;// ww w. java2s.c om }
From source file:com.ali.truyentranh.fragment.CategoryFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.home_category, container, false); this.viewTab = view; ListView listView = (ListView) view.findViewById(R.id.listCategory); adapter = new StableArrayAdapter(MainActivity.context, null); listView.setAdapter(adapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override/*from ww w. ja v a 2 s . c om*/ public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { Category item = (Category) adapter.getItem(position); Intent myIntent = new Intent(MainActivity.context, CategoryActivity.class); myIntent.putExtra("category", item.toString()); MainActivity.context.startActivity(myIntent); } }); return view; }
From source file:com.android.projectz.teamrocket.thebusapp.settings.SettingGeneralActivity.java
/** * Metodo che serve a far visualizzare la lista con le relative personalizzazioni all'interno della schermata * <p>/*www .j a v a 2 s .c o m*/ * ho deciso di fare ci in modo tale da richiamare il metodo quando la lingua viene cambiata, cosi la vista * aggiornata con la lingua selezionata */ @Override protected void onStart() { super.onStart(); String[] settingText = { getResources().getString(R.string.setting_theme), getResources().getString(R.string.setting_instrictions) }; String[] settingSubtext = { SharedPreferencesUtils.getSelectedTheme(SettingGeneralActivity.this).equals("AppTheme") ? "Light" : "Dark", getResources().getString(R.string.short_instruction) }; Resources res = getResources(); Drawable[] settingImg = { ContextCompat.getDrawable(this, R.drawable.ic_theme_chooser), ContextCompat.getDrawable(this, R.drawable.ic_instruction) }; CustomListSettingOther adapter = new CustomListSettingOther(SettingGeneralActivity.this, settingText, settingSubtext, settingImg); ListView list = (ListView) findViewById(R.id.general_setting_list); list.setAdapter(adapter); list.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { switch (position) { case 0: new MaterialDialog.Builder(SettingGeneralActivity.this).title(R.string.dialog_title_theme) .items(R.array.theme) .itemsCallbackSingleChoice( SharedPreferencesUtils.getSelectedTheme(SettingGeneralActivity.this) .equals("AppTheme") ? 0 : 1, new MaterialDialog.ListCallbackSingleChoice() { @Override public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) { try { SharedPreferencesUtils.setSelectedTheme(SettingGeneralActivity.this, text.equals("Light") ? "AppTheme" : "ThemeDark"); reload(); } catch (Exception e) { e.printStackTrace(); SharedPreferencesUtils.setSelectedLanguage( SettingGeneralActivity.this, "AppTheme"); } return true; } }) .positiveText(R.string.dialog_ok_button).show(); break; case 1: Intent inst = new Intent(SettingGeneralActivity.this, IntroApp.class); startActivity(inst); SettingGeneralActivity.this.overridePendingTransition(R.anim.anim_slide_in_right, R.anim.anim_slide_out_right); break; } } }); }
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()); }/* w w w . ja v a2 s . c o m*/ 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); } }
From source file:com.othermedia.exampleasyncimage.AsyncImageDemo.java
/** Called when the activity is first created. */ @Override/*from ww w .jav a 2s . c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // -- AsyncImage initialization: AsyncImageRegistry.initialize(getApplicationContext()); /* Example of using AsyncImage with a single ImageView * AsyncImageCache defaultCache = AsyncImageRegistry.getInstance().getDefaultCache(); ImageView remotePhoto = new ImageView(getApplicationContext()); this.setContentView(remotePhoto); defaultCache.loadRemoteImage(remotePhoto, // <- target ImageView "http://www.othermedia.com/data/images/originals/office-263.jpg", // <- bitmap URL R.drawable.imageplaceholder); // <- optionally, default resource to show when downloading */ // -- Register a special cache just for our Twitter Avatars with file caching "on" AsyncImageRegistry.getInstance().registerCache(AsyncImageDemo.AVATARS_CACHE, true); // -- Setting up the example: userList = new ArrayList<SampleTweet>(); sampleAdapter = new SampleAdapter(getApplicationContext(), userList); ListView list = new ListView(getApplicationContext()); list.setAdapter(sampleAdapter); setContentView(list); // Get the first portion of Twitter Users talking about Android :) (new TwitterDownloader()).execute(); // -- AsyncImage hook up ListView to the cache (for holding up new downloads - it's optional) // AsyncImageRegistry.getInstance().getRegisteredCache(LOGOS_CACHE).installScrollListnerOn(list); // Or, do it Manually, if you need a custom OnScrollListener list.setOnScrollListener(new OnScrollListener() { // This holds up the Cache's Download Queue public void onScrollStateChanged(AbsListView listView, int scrollState) { if (scrollState == OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) AsyncImageRegistry.getInstance().getRegisteredCache(AVATARS_CACHE).holdQueue(); if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) AsyncImageRegistry.getInstance().getRegisteredCache(AVATARS_CACHE).resumeQueue(); } // This loads more items once the ListView reaches the bottom public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (firstVisibleItem + visibleItemCount == totalItemCount && currentPage < 20 && !downloaderRunning) { currentPage++; (new TwitterDownloader()).execute(); } } }); Toast.makeText(getApplicationContext(), "Loading...", 1000).show(); }