Java Code Examples for android.widget.ListView.getCount()

The following are Jave code examples for showing how to use getCount() of the android.widget.ListView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: CSipSimple   File: CallLogListFragment.java   View Source Code Vote up 10 votes
private void actionModeDialpad() {
    
    ListView lv = getListView();

    for(int i = 0; i < lv.getCount(); i++) {
        if(lv.isItemChecked(i)) {
            mAdapter.getItem(i);
            String number = mAdapter.getCallRemoteAtPostion(i);
            if(!TextUtils.isEmpty(number)) {
                Intent it = new Intent(Intent.ACTION_DIAL);
                it.setData(SipUri.forgeSipUri(SipManager.PROTOCOL_SIP, number));
                startActivity(it);
            }
            break;
        }
    }
    mMode.invalidate();
    
}
 
Example 2
Project: CSipSimple   File: CallLogListFragment.java   View Source Code Vote up 7 votes
private void actionModeDelete() {
    ListView lv = getListView();
    
    ArrayList<Long> checkedIds = new ArrayList<Long>();
    
    for(int i = 0; i < lv.getCount(); i++) {
        if(lv.isItemChecked(i)) {
            long[] selectedIds = mAdapter.getCallIdsAtPosition(i);
            
            for(long id : selectedIds) {
                checkedIds.add(id);
            }
            
        }
    }
    if(checkedIds.size() > 0) {
        String strCheckedIds = TextUtils.join(", ", checkedIds);
        Log.d(THIS_FILE, "Checked positions ("+ strCheckedIds +")");
        getActivity().getContentResolver().delete(SipManager.CALLLOG_URI, Calls._ID + " IN ("+strCheckedIds+")", null);
        mMode.finish();
    }
}
 
Example 3
Project: q-mail   File: K9ListActivity.java   View Source Code Vote up 6 votes
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // Shortcuts that work no matter what is selected
    if (QMail.useVolumeKeysForListNavigationEnabled() &&
            (keyCode == KeyEvent.KEYCODE_VOLUME_UP ||
            keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {

        final ListView listView = getListView();

        int currentPosition = listView.getSelectedItemPosition();
        if (currentPosition == AdapterView.INVALID_POSITION || listView.isInTouchMode()) {
            currentPosition = listView.getFirstVisiblePosition();
        }

        if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && currentPosition > 0) {
            listView.setSelection(currentPosition - 1);
        } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN &&
                currentPosition < listView.getCount()) {
            listView.setSelection(currentPosition + 1);
        }

        return true;
    }

    return super.onKeyDown(keyCode, event);
}
 
Example 4
Project: ultrasonic   File: SelectAlbumActivity.java   View Source Code Vote up 6 votes
private static List<MusicDirectory.Entry> getSelectedSongs(ListView albumListView)
{
	List<MusicDirectory.Entry> songs = new ArrayList<MusicDirectory.Entry>(10);

	if (albumListView != null)
	{
		int count = albumListView.getCount();
		for (int i = 0; i < count; i++)
		{
			if (albumListView.isItemChecked(i))
			{
				songs.add((MusicDirectory.Entry) albumListView.getItemAtPosition(i));
			}
		}
	}

	return songs;
}
 
Example 5
Project: ultrasonic   File: BookmarkActivity.java   View Source Code Vote up 6 votes
private static List<MusicDirectory.Entry> getSelectedSongs(ListView albumListView)
{
	List<MusicDirectory.Entry> songs = new ArrayList<MusicDirectory.Entry>(10);

	if (albumListView != null)
	{
		int count = albumListView.getCount();
		for (int i = 0; i < count; i++)
		{
			if (albumListView.isItemChecked(i))
			{
				songs.add((MusicDirectory.Entry) albumListView.getItemAtPosition(i));
			}
		}
	}

	return songs;
}
 
Example 6
Project: letv   File: ListViewAutoScrollHelper.java   View Source Code Vote up 6 votes
public boolean canTargetScrollVertically(int direction) {
    ListView target = this.mTarget;
    int itemCount = target.getCount();
    if (itemCount == 0) {
        return false;
    }
    int childCount = target.getChildCount();
    int firstPosition = target.getFirstVisiblePosition();
    int lastPosition = firstPosition + childCount;
    if (direction > 0) {
        if (lastPosition >= itemCount && target.getChildAt(childCount - 1).getBottom() <= target.getHeight()) {
            return false;
        }
    } else if (direction >= 0) {
        return false;
    } else {
        if (firstPosition <= 0 && target.getChildAt(0).getTop() >= 0) {
            return false;
        }
    }
    return true;
}
 
Example 7
Project: Android-DFU-App   File: UARTLogFragment.java   View Source Code Vote up 6 votes
@Override
public void onLoadFinished(final Loader<Cursor> loader, final Cursor data) {
	// Here we have to restore the old saved scroll position, or scroll to the bottom if before adding new events it was scrolled to the bottom.  
	final ListView list = getListView();
	final int position = mLogScrollPosition;
	final boolean scrolledToBottom = position == LOG_SCROLLED_TO_BOTTOM || (list.getCount() > 0 && list.getLastVisiblePosition() == list.getCount() - 1);

	mLogAdapter.swapCursor(data);

	if (position > LOG_SCROLL_NULL) {
		list.setSelectionFromTop(position, 0);
	} else {
		if (scrolledToBottom)
			list.setSelection(list.getCount() - 1);
	}
	mLogScrollPosition = LOG_SCROLL_NULL;
}
 
Example 8
Project: boohee_v5.6   File: ListViewAutoScrollHelper.java   View Source Code Vote up 6 votes
public boolean canTargetScrollVertically(int direction) {
    ListView target = this.mTarget;
    int itemCount = target.getCount();
    if (itemCount == 0) {
        return false;
    }
    int childCount = target.getChildCount();
    int firstPosition = target.getFirstVisiblePosition();
    int lastPosition = firstPosition + childCount;
    if (direction > 0) {
        if (lastPosition >= itemCount && target.getChildAt(childCount - 1).getBottom() <= target.getHeight()) {
            return false;
        }
    } else if (direction >= 0) {
        return false;
    } else {
        if (firstPosition <= 0 && target.getChildAt(0).getTop() >= 0) {
            return false;
        }
    }
    return true;
}
 
Example 9
Project: rental-calc   File: ItemizationActivityTest.java   View Source Code Vote up 6 votes
private void addItem(Activity activity, String name, Integer value)
{
    ShadowActivity shadowActivity = shadowOf(activity);
    ListView list = (ListView)activity.findViewById(R.id.list);
    assertNotNull(list);

    int initialCount = list.getCount();

    shadowActivity.clickMenuItem(R.id.action_add);
    ItemizationAdapter adapter = (ItemizationAdapter)list.getAdapter();
    Itemization listItem = adapter.getItem(initialCount);
    assertNotNull(listItem);
    listItem.name = name;
    listItem.value = value;

    assertEquals(initialCount+1, list.getCount());
}
 
Example 10
Project: rental-calc   File: ItemizationActivityTest.java   View Source Code Vote up 6 votes
private void addItems(Activity activity, Map<String, Integer> items)
{
    ListView list = (ListView)activity.findViewById(R.id.list);
    assertNotNull(list);

    ShadowListView shadowList = shadowOf(list);
    shadowList.populateItems();

    int initialCount = list.getCount();

    for(Map.Entry<String, Integer> item : items.entrySet())
    {
        addItem(activity, item.getKey(), item.getValue());
    }

    assertEquals(initialCount + items.size(), list.getCount());
}
 
Example 11
Project: CSipSimple   File: CallLogListFragment.java   View Source Code Vote up 5 votes
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
    Log.d(THIS_FILE, "onPrepareActionMode");
    ListView lv = getListView();
    int nbrCheckedItem = 0;

    for (int i = 0; i < lv.getCount(); i++) {
        if (lv.isItemChecked(i)) {
            nbrCheckedItem++;
        }
    }
    menu.findItem(R.id.delete).setVisible(nbrCheckedItem > 0);
    menu.findItem(R.id.dialpad).setVisible(nbrCheckedItem == 1);
    return false;
}
 
Example 12
Project: CSipSimple   File: CallLogListFragment.java   View Source Code Vote up 5 votes
private void actionModeInvertSelection() {
    ListView lv = getListView();

    for(int i = 0; i < lv.getCount(); i++) {
        lv.setItemChecked(i, !lv.isItemChecked(i));
    }
    mMode.invalidate();
}
 
Example 13
Project: Android-DFU-App   File: UARTLogFragment.java   View Source Code Vote up 5 votes
@Override
public void onSaveInstanceState(final Bundle outState) {
	super.onSaveInstanceState(outState);

	// Save the last log list view scroll position
	final ListView list = getListView();
	final boolean scrolledToBottom = list.getCount() > 0 && list.getLastVisiblePosition() == list.getCount() - 1;
	outState.putInt(SIS_LOG_SCROLL_POSITION, scrolledToBottom ? LOG_SCROLLED_TO_BOTTOM : list.getFirstVisiblePosition());
}
 
Example 14
Project: mobile-grammar   File: AllArticlesListViewActivity.java   View Source Code Vote up 4 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // load layout with activity
    ViewStub stub = (ViewStub) findViewById(R.id.layout_stub);
    stub.setLayoutResource(R.layout.layout_all_articles_list_view);
    View inflated = stub.inflate();
    // listview with articles
    articlesListViewItems = (ListView) findViewById(R.id.listViewArticles);
    // database init
    mDbHelper = new ArticlesDataSource(getApplicationContext());
    mDbHelper.createDatabase();
    mDbHelper.open();

    // get data from intent to define what's group to show
    long groupId = this.getIntent().getLongExtra("group_id", -1);
    statusToShow = (ActivityArticlesStatusToShow) this.getIntent().getSerializableExtra("status_what_show");
    String groupName = this.getIntent().getStringExtra("group_name");

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(getString(R.string.all_articles_menu_title));

    // if there is start activity, so show drawer
    if (groupId == 0 || groupId == -1) {
        initDrawer();
        articlesCursor = mDbHelper.getAllArticles();
    } else {
        // ... but if this activity is used to show short listview with articles, just show toolbar with back button
        initToolbarWithBackButton(groupName);
        articlesCursor = mDbHelper.getArticlesByGroup(groupId);
        sequenceIds = mDbHelper.getIdsOfGroup(groupId);
    }
    // listener of row click
    articlesListViewItems.setOnItemClickListener(listViewClickListener);

    // if we just open application - adapter has never been used, so create this
    if (articlesViewAdapter == null) {
        articlesViewAdapter = new ArticleCursorAdapter(this, articlesCursor, 0);
    } else
    /**
     * otherwise it means that this activity is used inside app - to show short list of articles
     * just change cursor
     */
        articlesViewAdapter.changeCursor(articlesCursor);

    // Attach cursor adapter to the ListView
    articlesListViewItems.setAdapter(articlesViewAdapter);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);

    // if row's count greater that limit ,,,
    if (articlesListViewItems.getCount() > LIMIT_TO_SHOW_SEARCH_FIELD) {
        // fab link to listview
        fab.attachToListView(articlesListViewItems);
        fab.setVisibility(View.VISIBLE);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // go to top of listview
                articlesListViewItems.setSelectionAfterHeaderView();
            }
        });
    }
    else {
        // otherwise - hide fab
        fab.setVisibility(View.INVISIBLE);
    }
}
 
Example 15
Project: android-api   File: IndoorMapView.java   View Source Code Vote up 4 votes
private int getListViewHeight(ListView list) {
    return list.getCount() * (int) ListItemHeight;
}