本文整理汇总了Java中android.widget.ListView.getCount方法的典型用法代码示例。如果您正苦于以下问题:Java ListView.getCount方法的具体用法?Java ListView.getCount怎么用?Java ListView.getCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.ListView
的用法示例。
在下文中一共展示了ListView.getCount方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: actionModeDialpad
import android.widget.ListView; //导入方法依赖的package包/类
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();
}
示例2: actionModeDelete
import android.widget.ListView; //导入方法依赖的package包/类
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();
}
}
示例3: onKeyDown
import android.widget.ListView; //导入方法依赖的package包/类
@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);
}
示例4: getSelectedSongs
import android.widget.ListView; //导入方法依赖的package包/类
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;
}
示例5: canTargetScrollVertically
import android.widget.ListView; //导入方法依赖的package包/类
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;
}
示例6: onLoadFinished
import android.widget.ListView; //导入方法依赖的package包/类
@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;
}
示例7: addItem
import android.widget.ListView; //导入方法依赖的package包/类
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());
}
示例8: addItems
import android.widget.ListView; //导入方法依赖的package包/类
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());
}
示例9: onPrepareActionMode
import android.widget.ListView; //导入方法依赖的package包/类
@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;
}
示例10: actionModeInvertSelection
import android.widget.ListView; //导入方法依赖的package包/类
private void actionModeInvertSelection() {
ListView lv = getListView();
for(int i = 0; i < lv.getCount(); i++) {
lv.setItemChecked(i, !lv.isItemChecked(i));
}
mMode.invalidate();
}
示例11: onSaveInstanceState
import android.widget.ListView; //导入方法依赖的package包/类
@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());
}
示例12: onCreate
import android.widget.ListView; //导入方法依赖的package包/类
@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);
}
}
示例13: getListViewHeight
import android.widget.ListView; //导入方法依赖的package包/类
private int getListViewHeight(ListView list) {
return list.getCount() * (int) ListItemHeight;
}