List of usage examples for android.widget ListView ListView
public ListView(Context context)
From source file:com.othermedia.exampleasyncimage.AsyncImageDemo.java
/** Called when the activity is first created. */ @Override/*from www . ja va 2 s .co 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(); }
From source file:sysnetlab.android.sdc.ui.fragments.ExperimentSensorSelectionFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.d("SensorDataCollector", "ExperimentSensorSelectionFragment::onCreateView(): " + "entered with mHavingHeader = " + mHavingHeader); mView = inflater.inflate(R.layout.fragment_sensor_selection, container, false); mHavingHeader = getActivity().getIntent().getBooleanExtra("havingheader", false); if (mHavingHeader) { RelativeLayout layout = (RelativeLayout) mView.findViewById(R.id.layout_sensor_selection_header); layout.setVisibility(View.VISIBLE); }//ww w . java2 s . c o m // find the container for the list RelativeLayout layout = (RelativeLayout) mView.findViewById(R.id.layout_sensor_selection_list); mListView = new ListView(getActivity()); if (!SensorDiscoverer.isInitialized()) SensorDiscoverer.initialize(getActivity().getApplicationContext()); List<AbstractSensor> lstSensors = SensorDiscoverer.discoverSensorList(); Activity activity = getActivity(); if (activity instanceof CreateExperimentActivity) { ((CreateExperimentActivity) activity).selectSensors(lstSensors); } else { Log.d("SensorDataCollector", "ExperimentSensorSelectionFragment::onCreate(): " + "not a CreateExperimentActivity."); } mSensorListAdaptor = new SensorListAdapter(getActivity(), lstSensors); mListView.setAdapter(mSensorListAdaptor); layout.addView(mListView); return mView; }
From source file:com.cuddlesoft.nori.fragment.TagListDialogFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Extract data from the arguments bundle. image = getArguments().getParcelable(BUNDLE_ID_IMAGE); settings = getArguments().getParcelable(BUNDLE_ID_SEARCH_CLIENT_SETTINGS); // Create and initialize the ListView. final ListView listView = new ListView(getActivity()); listView.setOnItemClickListener(this); listView.setAdapter(new TagListAdapter()); return new AlertDialog.Builder(getActivity()).setView(listView) .setPositiveButton(R.string.dialog_tags_closeButton, new DialogInterface.OnClickListener() { @Override// w ww .j a va2s .c o m public void onClick(DialogInterface dialogInterface, int i) { dismiss(); } }).create(); }
From source file:de.vanita5.twittnuker.fragment.support.DataExportImportTypeSelectorDialogFragment.java
@Override public final Dialog onCreateDialog(final Bundle savedInstanceState) { final Context context = getActivity(); final int flags = getEnabledFlags(); mAdapter = new TypeAdapter(context, flags); mListView = new ListView(context); mAdapter.add(new Type(R.string.settings, FLAG_PREFERENCES)); mAdapter.add(new Type(R.string.nicknames, FLAG_NICKNAMES)); mAdapter.add(new Type(R.string.user_colors, FLAG_USER_COLORS)); mAdapter.add(new Type(R.string.custom_host_mapping, FLAG_HOST_MAPPING)); mListView.setAdapter(mAdapter);//from ww w . j av a 2 s .c om mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); mListView.setOnItemClickListener(this); for (int i = 0, j = mAdapter.getCount(); i < j; i++) { mListView.setItemChecked(i, mAdapter.isEnabled(i)); } final AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(getTitle()); builder.setView(mListView); builder.setPositiveButton(android.R.string.ok, this); builder.setNegativeButton(android.R.string.cancel, null); final AlertDialog dialog = builder.create(); dialog.setOnShowListener(this); return dialog; }
From source file:org.mariotaku.twidere.fragment.support.DataExportImportTypeSelectorDialogFragment.java
@NonNull @Override/* w w w.ja v a 2 s.c o m*/ public final Dialog onCreateDialog(final Bundle savedInstanceState) { final Context context = getActivity(); final int flags = getEnabledFlags(); mAdapter = new TypeAdapter(context, flags); mListView = new ListView(context); mAdapter.add(new Type(R.string.settings, DataImportExportUtils.FLAG_PREFERENCES)); mAdapter.add(new Type(R.string.nicknames, DataImportExportUtils.FLAG_NICKNAMES)); mAdapter.add(new Type(R.string.user_colors, DataImportExportUtils.FLAG_USER_COLORS)); mAdapter.add(new Type(R.string.custom_host_mapping, DataImportExportUtils.FLAG_HOST_MAPPING)); mAdapter.add(new Type(R.string.keyboard_shortcuts, DataImportExportUtils.FLAG_KEYBOARD_SHORTCUTS)); mListView.setAdapter(mAdapter); mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); mListView.setOnItemClickListener(this); for (int i = 0, j = mAdapter.getCount(); i < j; i++) { mListView.setItemChecked(i, mAdapter.isEnabled(i)); } final AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(getTitle()); builder.setView(mListView); builder.setPositiveButton(android.R.string.ok, this); builder.setNegativeButton(android.R.string.cancel, null); final AlertDialog dialog = builder.create(); dialog.setOnShowListener(this); return dialog; }
From source file:org.mariotaku.twidere.fragment.DataExportImportTypeSelectorDialogFragment.java
@NonNull @Override/*w w w.ja v a 2 s . co m*/ public final Dialog onCreateDialog(final Bundle savedInstanceState) { final Context context = getActivity(); final int flags = getEnabledFlags(); mAdapter = new TypeAdapter(context, flags); mListView = new ListView(context); mAdapter.add(new Type(R.string.settings, DataImportExportUtils.FLAG_PREFERENCES)); mAdapter.add(new Type(R.string.nicknames, DataImportExportUtils.FLAG_NICKNAMES)); mAdapter.add(new Type(R.string.user_colors, DataImportExportUtils.FLAG_USER_COLORS)); mAdapter.add(new Type(R.string.custom_host_mapping, DataImportExportUtils.FLAG_HOST_MAPPING)); mAdapter.add(new Type(R.string.keyboard_shortcuts, DataImportExportUtils.FLAG_KEYBOARD_SHORTCUTS)); mAdapter.add(new Type(R.string.filters, DataImportExportUtils.FLAG_FILTERS)); mAdapter.add(new Type(R.string.tabs, DataImportExportUtils.FLAG_TABS)); mListView.setAdapter(mAdapter); mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); mListView.setOnItemClickListener(this); for (int i = 0, j = mAdapter.getCount(); i < j; i++) { mListView.setItemChecked(i, mAdapter.isEnabled(i)); } final AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(getTitle()); builder.setView(mListView); builder.setPositiveButton(android.R.string.ok, this); builder.setNegativeButton(android.R.string.cancel, null); final AlertDialog dialog = builder.create(); dialog.setOnShowListener(this); return dialog; }
From source file:com.balch.android.app.framework.preference.PreferenceFragment.java
@Override public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle savedInstanceState) { ListView listView = new ListView(getActivity()); listView.setId(android.R.id.list);//from ww w .j ava 2s . co m if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { final int horizontalPadding = (int) (HC_HORIZONTAL_PADDING * getResources().getDisplayMetrics().density); listView.setPadding(horizontalPadding, 0, horizontalPadding, 0); } return listView; }
From source file:jahirfiquitiva.iconshowcase.fragments.base.PreferenceFragment.java
@Override public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle savedInstanceState) { ListView listView = new ListView(getActivity()); listView.setId(android.R.id.list);/*w w w . j ava 2s .c o m*/ listView.setDividerHeight(0); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { HC_HORIZONTAL_PADDING = 5.33; } final int horizontalPadding = (int) (HC_HORIZONTAL_PADDING * getResources().getDisplayMetrics().density); listView.setPadding(horizontalPadding, 0, horizontalPadding, 0); } return listView; }
From source file:de.gebatzens.ggvertretungsplan.fragment.NewsFragment.java
@Override public void createView(LayoutInflater inflater, ViewGroup view) { lv = new ListView(getActivity()); int p = toPixels(10); //lv.getDivider().setColorFilter(GGApp.GG_APP.provider.getColor(), PorterDuff.Mode.ADD); lv.setDrawSelectorOnTop(true);//from ww w . ja v a 2 s. c o m lv.setDivider(getResources().getDrawable(R.drawable.listview_divider)); ((LinearLayout) view.findViewById(R.id.news_content)).addView(lv); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { TextView txtTitle = (TextView) view.findViewById(R.id.newsTitle); TextView txtContent = (TextView) view.findViewById(R.id.newsContent); String mTitle = txtTitle.getText().toString(); String mContent = txtContent.getText().toString(); AlertDialog.Builder ad = new AlertDialog.Builder(view.getContext()); ad.setTitle(mTitle); ad.setMessage(mContent); ad.setNegativeButton(GGApp.GG_APP.getResources().getString(R.string.close), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); ad.show(); if (!mDatabaseHelper.checkNewsRead(mTitle)) { mDatabaseHelper.addReadNews(mTitle); nfla.notifyDataSetChanged(); } } }); nfla = new NewsFragmentListAdapter(getActivity(), GGApp.GG_APP.news); lv.setAdapter(nfla); }
From source file:me.xiaopan.android.inject.sample.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); listView = new ListView(getBaseContext()); setContentView(listView);//from ww w.ja v a2s . c om // SharedPreferences? PreferenceUtils.putBoolean(getBaseContext(), KEY_BOOLEAN, true); PreferenceUtils.putFloat(getBaseContext(), KEY_FLOAT, 10000f); PreferenceUtils.putInt(getBaseContext(), KEY_INT, 2000); PreferenceUtils.putLong(getBaseContext(), KEY_LONG, 50000); PreferenceUtils.putString(getBaseContext(), KEY_STRING, "Preference String"); Set<String> stringSet = new HashSet<String>(); stringSet.add("String Set 1"); stringSet.add("String Set 2"); stringSet.add("String Set 3"); stringSet.add("String Set 4"); PreferenceUtils.putStringSet(getBaseContext(), KEY_STRING_SET, stringSet); MyBean bean2 = new MyBean(); bean2.setEmail("sky@xiaopan.me2"); bean2.setName("?2"); bean2.setSex("2"); PreferenceUtils.putObject(getBaseContext(), KEY_JSON, bean2); PreferenceUtils.putString(getBaseContext(), KEY_ENUM, Sex.WOMAN.name()); // ?? String[] items = new String[] { "", "?", "FragmentDialog", "InjectAdapter", "InjectExpandableListAdapter" }; listView.setAdapter(new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1, android.R.id.text1, items)); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position <= 2) { Bundle bundle = new Bundle(); bundle.putBoolean(MainActivity.PARAM_BOOLEAN, true); bundle.putBooleanArray(MainActivity.PARAM_BOOLEAN_ARRAY, new boolean[] { true, false, true }); bundle.putByte(MainActivity.PARAM_BYTE, (byte) 110); bundle.putByteArray(MainActivity.PARAM_BYTE_ARRAY, new byte[] { 111, 112, 113 }); bundle.putChar(MainActivity.PARAM_CHAR, 'R'); bundle.putCharArray(MainActivity.PARAM_CHAR_ARRAY, new char[] { 'c', 'h', 'a', 'r' }); bundle.putCharSequence(MainActivity.PARAM_CHAR_SEQUENCE, "CharSequence"); bundle.putCharSequenceArray(MainActivity.PARAM_CHAR_SEQUENCE_ARRAY, new CharSequence[] { "Char", " ", "Sequence" }); bundle.putDouble(MainActivity.PARAM_DOUBLE, 12.00d); bundle.putDoubleArray(MainActivity.PARAM_DOUBLE_ARRAY, new double[] { 12.01d, 12.02d, 12.03d }); bundle.putFloat(MainActivity.PARAM_FLOAT, 13.00f); bundle.putFloatArray(MainActivity.PARAM_FLOAT_ARRAY, new float[] { 13.01f, 13.02f, 13.03f }); bundle.putInt(MainActivity.PARAM_INT, 120); bundle.putIntArray(MainActivity.PARAM_INT_ARRAY, new int[] { 121, 122, 123, }); bundle.putLong(MainActivity.PARAM_LONG, 12345); bundle.putLongArray(MainActivity.PARAM_LONG_ARRAY, new long[] { 12346, 12347, 12348 }); bundle.putShort(MainActivity.PARAM_SHORT, (short) 2); bundle.putShortArray(MainActivity.PARAM_SHORT_ARRAY, new short[] { 3, 4, 5 }); bundle.putString(MainActivity.PARAM_STRING, "String"); bundle.putStringArray(MainActivity.PARAM_STRING_ARRAY, new String[] { "String1", "String2", "String3" }); // ??JSONBundle MyBean bean = new MyBean(); bean.setEmail("sky@xiaopan.me"); bean.setName("?"); bean.setSex(""); bundle.putString(PARAM_STRING_JSON, new Gson().toJson(bean)); bundle.putString(MainActivity.PARAM_STRING_ENUM, Sex.WOMAN.name()); // ArrayList<String> stringList = new ArrayList<String>(); stringList.add("ArrayList String 1"); stringList.add("ArrayList String 2"); stringList.add("ArrayList String 3"); bundle.putStringArrayList(MainActivity.PARAM_STRING_ARRAY_LIST, stringList); switch (position) { case 0: Second.SECOND_CHRONOGRAPH.lap(); Intent intent = new Intent(getBaseContext(), InjectTestActivity.class); intent.putExtras(bundle); startActivity(intent); break; case 1: Second.SECOND_CHRONOGRAPH.lap(); Intent intent2 = new Intent(getBaseContext(), NormalActivity.class); intent2.putExtras(bundle); startActivity(intent2); break; case 2: Second.SECOND_CHRONOGRAPH.lap(); new TestDialogFragment().show(getSupportFragmentManager(), ""); break; } } else { Class<?> targetClass = null; if (position == 3) { targetClass = InjectAdapterActivity.class; } else if (position == 4) { targetClass = InjectExpandableListAdapterActivity.class; } if (targetClass != null) { startActivity(new Intent(getBaseContext(), targetClass)); } } } }); }