Android AbsListView - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android AbsListView class.

This code example shows how to use the following methods:getChildAt, performItemClick, getAdapter
	} 
 
	@Test 
	public void is_item_click_available_from_list_fragment() { 
		ListView listView = (ListView) myListFragment.findViewById(android.R.id.list);
		long itemId = listView.getAdapter().getItemId(TESTED_CLICKED_INDEX);
		View view = listView.getChildAt(TESTED_CLICKED_INDEX);
 
		assertThat(myListFragment.listItemClicked).isFalse();
		listView.performItemClick(view, TESTED_CLICKED_INDEX, itemId);
		assertThat(myListFragment.listItemClicked).isTrue();
	} 
 
	public static void startFragment(Fragment fragment) {
		FragmentManager fragmentManager = new FragmentActivity().getSupportFragmentManager();
		FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
		fragmentTransaction.add(fragment, null);
		fragmentTransaction.commit();
	} 
} 
7
CodeRank
This code example shows how to use the following methods:setFastScrollEnabled, setDividerHeight
 
    } 
 
    @Override 
    protected void configureList(Activity activity, ListView listView) {
        super.configureList(activity, listView);
 
        listView.setFastScrollEnabled(true);
        listView.setDividerHeight(0);
 
        getListAdapter() 
                .addHeader(activity.getLayoutInflater()
                        .inflate(R.layout.news_list_item_labels, null));
    } 
 
    @Override 
    LogoutService getLogoutService() { 
        return logoutService;
    } 
 
8
CodeRank
This code example shows how to use the following methods:setOnTouchListener, setAdapter, setOnScrollListener, setOnItemSelectedListener
            // before the item manager was installed. 
            setAdapterOnView(wrapAdapter(itemManager, mWrappedAdapter));
        } else { 
            // Restore the listeners set on the view before the item 
            // manager was installed. 
            mAbsListView.setOnScrollListener(mOnScrollListener);
            mAbsListView.setOnTouchListener(mOnTouchListener);
            mAbsListView.setOnItemSelectedListener(mOnItemSelectedListener);
 
            // Remove wrapper adapter and re-apply the original one 
            setAdapterOnView(mWrappedAdapter);
        } 
 
        mItemManager = itemManager;
        mInstallingManager = false;
    } 
 
    AbsListView getAbsListView() {
        return mAbsListView;
    } 

8
CodeRank
This code example shows how to use the following methods:setOnTouchListener, setOnScrollListener, getAdapter, setAdapter
8
CodeRank
This code example shows how to use the following methods:setFastScrollEnabled, setDividerHeight
 
    } 
 
    @Override 
    protected void configureList(Activity activity, ListView listView) {
        super.configureList(activity, listView);
 
        listView.setFastScrollEnabled(true);
        listView.setDividerHeight(0);
 
        getListAdapter().addHeader(activity.getLayoutInflater()
                        .inflate(R.layout.user_list_item_labels, null));
    } 
 
    @Override 
    LogoutService getLogoutService() { 
        return logoutService;
    } 
 
 
8
CodeRank
This code example shows how to use the following methods:getChildAt, getChildCount, getListPaddingTop, getAdapter
                newLastChild.getId());
    } 
     
    @LargeTest 
    public void testShortScroll() { 
        View firstChild = mListView.getChildAt(0);
        if (firstChild.getTop() < this.mListView.getListPaddingTop()) {
            firstChild = mListView.getChildAt(1);
        } 
             
        View lastChild = mListView.getChildAt(mListView.getChildCount() - 1);
         
        int lastTop = lastChild.getTop();
         
        TouchUtils.dragViewBy(this, firstChild, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL,
                0, ViewConfiguration.getTouchSlop() + 1 + 10);
         
        View newLastChild = mListView.getChildAt(mListView.getChildCount() - 1);
         
        assertEquals("View scrolled to wrong position", lastTop, newLastChild.getTop() - 10);

8
CodeRank
This code example shows how to use the following methods:clearChoices, setItemChecked
   
  @Override 
  public boolean onItemLongClick(AdapterView<?> view, View row,
                                 int position, long id) {
    lastPosition=position;
    modeView.clearChoices();
    modeView.setItemChecked(lastPosition, true);
 
    if (activeMode==null) {
      activeMode=host.startActionMode(this);
    } 
 
    return(true); 
  } 
 
  @Override 
  public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    MenuInflater inflater=host.getMenuInflater();
 
    inflater.inflate(R.menu.context, menu);
7
CodeRank
This code example shows how to use the following methods:scrollToBottom, getHeight, getChildAt, getChildCount, getListPaddingBottom
                firstChild.getTop());
    } 
     
    @LargeTest 
    public void testPushUp() { 
        int originalCount = mListView.getChildCount();
         
        TouchUtils.scrollToBottom(this, mListView);
 
        // Nothing should be selected 
        assertEquals("Selection still available after touch", -1, 
                mListView.getSelectedItemPosition());
 
        View lastChild = mListView.getChildAt(mListView.getChildCount() - 1);
 
        assertEquals("List is not scrolled to the bottom", mListView.getAdapter().getCount() - 1,
                lastChild.getId());
 
        assertEquals("Last item is not touching the bottom edge",  
                mListView.getHeight() - mListView.getListPaddingBottom(), lastChild.getBottom());

7
CodeRank
This code example shows how to use the following methods:setOnTouchListener, setOnScrollListener, setOnItemSelectedListener
        if (mManaged != null) {
            AbsListView absListView = mManaged.getAbsListView();
 
            // These listeners will still run the current list view 
            // listeners as delegates. See ItemManaged. 
            absListView.setOnScrollListener(new ScrollManager());
            absListView.setOnTouchListener(new FingerTracker());
            absListView.setOnItemSelectedListener(new SelectionTracker());
        } 
    } 
 
    void loadItem(View itemView, int position) {
        AbsListView absListView = mManaged.getAbsListView();
        Adapter adapter = absListView.getAdapter();
 
        boolean shouldDisplayItem =
                (mScrollState != OnScrollListener.SCROLL_STATE_FLING && !mPendingItemsUpdate);
 
        // This runs on each Adapter.getView() call. Will only trigger an 
        // actual item loading request if the view is not being flung or finger 
7
CodeRank
This code example shows how to use the following methods:getChoiceMode, setChoiceMode, setItemChecked, getOnItemClickListener, getPositionForView
	private boolean isChosen(ListView listView, int position) {
		return listView.isItemChecked(position);
	} 
 
	private void setChosen(ListView listView, int position, boolean chosen) {
		if (chosen && listView.getChoiceMode() == ListView.CHOICE_MODE_NONE) {
			listener = listView.getOnItemClickListener();
 
			listView.setOnItemClickListener(null);
 
			listView.setChoiceMode(choiceMode);
		} 
 
		listView.setItemChecked(position, chosen);
 
		changed(listView, position);
	} 
 
	/** 
	 * Notification of a change at the given position. 

7
CodeRank

Related Android AbsListView Questions & Answers:

See Code Examples for Android AbsListView Methods: