List of usage examples for android.widget ListAdapter getCount
int getCount();
From source file:com.lgallardo.youtorrentcontroller.TorrentDetailsFragment.java
/** * *//w w w .j a v a2s.co m * Method for Setting the Height of the ListView dynamically. Hack to fix * the issue of not showing all the items of the ListView when placed inside * a ScrollView * ** */ public static void setListViewHeightBasedOnChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) return; int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.UNSPECIFIED); int totalHeight = 0; View view = null; for (int i = 0; i < listAdapter.getCount(); i++) { long numOfLines = 1; view = listAdapter.getView(i, view, listView); if (i == 0) { view.setLayoutParams(new LayoutParams(desiredWidth, LayoutParams.WRAP_CONTENT)); } view.measure(desiredWidth, MeasureSpec.UNSPECIFIED); TextView file = (TextView) view.findViewById(R.id.file); TextView info = (TextView) view.findViewById(R.id.info); if (view.getMeasuredWidth() > desiredWidth) { double viewWidthLong = Double.valueOf(view.getMeasuredWidth()); double desiredWidthLong = Double.valueOf(desiredWidth); numOfLines = Math.round(viewWidthLong / desiredWidthLong) + 1; totalHeight += file.getMeasuredHeight() * numOfLines + info.getMeasuredHeight(); } else { totalHeight += view.getMeasuredHeight(); } } LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); listView.setLayoutParams(params); listView.requestLayout(); }
From source file:com.wheelly.fragments.LocationsListFragment.java
private int getItemPositionByAdapterId(final long id) { final ListAdapter adapter = getListAdapter(); int i = 0;//from ww w . j a v a 2 s . co m while (i < adapter.getCount() && id != adapter.getItemId(i++)) ; return i == adapter.getCount() && id != adapter.getItemId(i - 1) ? -1 : --i; }
From source file:org.mozilla.gecko.tests.AboutHomeTest.java
protected View getDisplayedBookmark(String url) { openAboutHomeTab(AboutHomeTabs.BOOKMARKS); mSolo.hideSoftKeyboard();//from w w w . j av a 2 s.c om getInstrumentation().waitForIdleSync(); ListView bookmarksTabList = findListViewWithTag(HomePager.LIST_TAG_BOOKMARKS); waitForNonEmptyListToLoad(bookmarksTabList); ListAdapter adapter = bookmarksTabList.getAdapter(); if (adapter != null) { for (int i = 0; i < adapter.getCount(); i++) { // I am unable to click the view taken with getView for some reason so getting the child at i bookmarksTabList.smoothScrollToPosition(i); View bookmarkView = bookmarksTabList.getChildAt(i); if (bookmarkView instanceof android.widget.LinearLayout) { ViewGroup bookmarkItemView = (ViewGroup) bookmarkView; for (int j = 0; j < bookmarkItemView.getChildCount(); j++) { View bookmarkContent = bookmarkItemView.getChildAt(j); if (bookmarkContent instanceof android.widget.LinearLayout) { ViewGroup bookmarkItemLayout = (ViewGroup) bookmarkContent; for (int k = 0; k < bookmarkItemLayout.getChildCount(); k++) { // Both the title and url are represented as text views so we can cast the view without any issues TextView bookmarkTextContent = (TextView) bookmarkItemLayout.getChildAt(k); if (url.equals(bookmarkTextContent.getText().toString())) { return bookmarkView; } } } } } } } return null; }
From source file:org.droidupnp.view.SettingsActivity.java
public void setListAdapter(ListAdapter adapter) { if (mHeaders == null) { mHeaders = new ArrayList<Header>(); for (int i = 0; i < adapter.getCount(); ++i) mHeaders.add((Header) adapter.getItem(i)); }/*from w w w . ja v a 2 s . c om*/ super.setListAdapter(new MyPrefsHeaderAdapter(this, mHeaders)); }
From source file:com.oakesville.mythling.prefs.PrefsActivity.java
@Override public void setListAdapter(ListAdapter adapter) { if (headers == null) { headers = new ArrayList<Header>(); // when the saved state provides the list of headers, onBuildHeaders() is not called // so we build it from the adapter provided, then use our own adapter for (int i = 0; i < adapter.getCount(); i++) headers.add((Header) adapter.getItem(i)); }// w w w .j av a2 s . c om super.setListAdapter(new HeaderListAdapter(this, headers)); }
From source file:com.moonpi.tapunlock.MainActivity.java
public static void updateListViewHeight(ListView myListView) { ListAdapter myListAdapter = myListView.getAdapter(); if (myListAdapter == null) return;//from www.j av a 2 s . com // Get listView height int totalHeight = myListView.getPaddingTop() + myListView.getPaddingBottom(); int adapterCount = myListAdapter.getCount(); for (int i = 0; i < adapterCount; i++) { View listItem = myListAdapter.getView(i, null, myListView); if (listItem instanceof ViewGroup) { listItem.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); } listItem.measure(0, 0); totalHeight += listItem.getMeasuredHeight(); } // Change height of listView ViewGroup.LayoutParams paramsList = myListView.getLayoutParams(); paramsList.height = totalHeight + (myListView.getDividerHeight() * (adapterCount - 1)); myListView.setLayoutParams(paramsList); }
From source file:org.wikipedia.page.bottomcontent.BottomContentHandler.java
private void layoutContent() { if (!parentFragment.isAdded()) { return;//from w w w. j a va2s . com } bottomContentContainer.setVisibility(View.INVISIBLE); // keep trying until our layout has a height... if (bottomContentContainer.getHeight() == 0) { final int postDelay = 50; bottomContentContainer.postDelayed(new Runnable() { @Override public void run() { layoutContent(); } }, postDelay); return; } // calculate the height of the listview, based on the number of items inside it. ListAdapter adapter = readMoreList.getAdapter(); if (adapter != null && adapter.getCount() > 0) { ViewGroup.LayoutParams params = readMoreList.getLayoutParams(); final int itemHeight = (int) activity.getResources().getDimension(R.dimen.defaultListItemSize); params.height = adapter.getCount() * itemHeight + (readMoreList.getDividerHeight() * (adapter.getCount() - 1)); readMoreList.setLayoutParams(params); } readMoreList.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); bottomContentContainer.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); // pad the bottom of the webview, to make room for ourselves int totalHeight = bottomContentContainer.getMeasuredHeight(); JSONObject payload = new JSONObject(); try { payload.put("paddingBottom", (int) (totalHeight / displayDensity)); } catch (JSONException e) { throw new RuntimeException(e); } bridge.sendMessage("setPaddingBottom", payload); // ^ sending the padding event will guarantee a ContentHeightChanged event to be triggered, // which will update our margin based on the scroll offset, so we don't need to do it here. }
From source file:dev.drsoran.moloko.fragments.AbstractTasksListFragment.java
@Override public T getTask(String taskId) { T task = null;//from w ww . j av a 2s .c o m final ListAdapter adapter = getListAdapter(); final int itemCount = adapter.getCount(); for (int i = 0; i < itemCount && task == null; i++) { @SuppressWarnings({ "unchecked" }) final T temp = (T) adapter.getItem(i); if (temp.getId().equals(taskId)) { task = temp; } } return task; }
From source file:com.lolay.android.ui.LolayBaseFragmentActivity.java
/** * Thanks to http://nex-otaku-en.blogspot.com/2010/12/android-put-listview-in-scrollview.html * WARNING: Only works with Linear Layouts or you'll get a NullPointerException in the measure code *//* ww w. j a va 2s. c o m*/ public void listViewSetHeightFromChildren(ListView listView) { ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) { // pre-condition return; } int totalHeight = 0; int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.AT_MOST); for (int i = 0; i < listAdapter.getCount(); i++) { View listItem = listAdapter.getView(i, null, listView); listItem.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED); totalHeight += listItem.getMeasuredHeight(); } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); listView.setLayoutParams(params); listView.requestLayout(); }
From source file:com.zphinx.sortattributes.SortDialogManager.java
/** * Specifies the actions that ovccur when a stateTextView object is clicked * * @param activity/* ww w . j a va 2 s . c om*/ * The activity hosting this dialogManager * @param adapter * The list adapter containing multiple stateview * @param position * The position of the stateview object been clicked * @throws NotFoundException * If the specified state textview is not available */ private void clickStateTextView(final Activity activity, final ListAdapter adapter, int position) throws NotFoundException { if (position > -1) { int count = adapter.getCount(); for (int i = 0; i < count; i++) { if (i != position) { StateTextView anon = (StateTextView) adapter.getItem(i); if ((anon != null)) { anon.setCompoundDrawables(null, null, null, null); anon.setSortDirection(StateTextView.SORT_UNINITIALIZED); } } } StateTextView rowView = (StateTextView) adapter.getItem(position); Drawable[] draws = rowView.getCompoundDrawables(); if (draws == null) { draws = new Drawable[4]; } Log.d(TAG, "The stateView is: ........................." + rowView); Log.d(TAG, "The drawable is is: ........................." + draws[2]); setCurrentImage(rowView, draws, activity); selectedIndex = position; } }