本文整理汇总了Java中android.widget.ListView.setSelection方法的典型用法代码示例。如果您正苦于以下问题:Java ListView.setSelection方法的具体用法?Java ListView.setSelection怎么用?Java ListView.setSelection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.ListView
的用法示例。
在下文中一共展示了ListView.setSelection方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: onCreate
import android.widget.ListView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_item_income);
dao = AccountItemDao.getInstance();
EventBus.getDefault().register(this);
itemListView = (ListView) findViewById(R.id.aii_item_list);
items = dao.findAllByExpense(0);
inflater = LayoutInflater.from(mContext);
itemListView.setAdapter(itemAdapter);
// itemListView.setOnItemClickListener(itemItemListener);
findViewById(R.id.aii_back).setOnClickListener(clickListener);
findViewById(R.id.aii_edit).setOnClickListener(clickListener);
if (!TextUtils.isEmpty(item)) {
for (int i = 0; i < items.size(); i++) {
if (items.get(i).getItem().equals(item)) {
seletectedItemPosition = i;
break;
}
}
}
itemListView.setSelection(seletectedItemPosition);
}
示例3: 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;
}
示例4: smoothScrollListView
import android.widget.ListView; //导入方法依赖的package包/类
public static void smoothScrollListView(ListView listView, int position) {
if (VERSION.SDK_INT >= 11) {
listView.smoothScrollToPositionFromTop(0, 0);
} else if (VERSION.SDK_INT >= 8) {
listView.smoothScrollToPosition(0);
} else {
listView.setSelection(position);
}
}
示例5: onCreate
import android.widget.ListView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
final String MEDIA_PATH = Environment.getExternalStorageDirectory().toString();
Log.d(TAG,MEDIA_PATH);
if (MainActivity.isFirstTime){
try {
copyResourcesToStorage(MEDIA_PATH);
} catch (IOException e) {
e.printStackTrace();
}
if (songsList.size()>0)songsList.clear();
ScanDirectory(MEDIA_PATH);
Log.d(TAG,"Songs_Found" + songsList.size());
}
else{
songsList.get(indexOfTrackSelected).setISsongSelected(false);
}
songsDisplayAdapter = new SongsDisplayAdapter(this,songsList);
ListView listView = (ListView) findViewById(R.id.Songs_List);
listView.setAdapter(songsDisplayAdapter);
listView.setSelection(indexOfTrackSelected);
}
示例6: scrollToTop
import android.widget.ListView; //导入方法依赖的package包/类
/**
* listview滚动到顶部
*
* @param animate 是否动画
* @return
*/
public UDBaseListOrRecyclerView scrollToTop(final int offset, final boolean animate) {
final ListView lv = getListView();
if (lv != null) {
if (animate) {
if (lv.getFirstVisiblePosition() > 7) {//hack fast scroll
lv.setSelection(7);
}
lv.smoothScrollToPositionFromTop(0, offset);
} else {
lv.setSelectionFromTop(0, offset);
}
}
return this;
}
示例7: onCreate
import android.widget.ListView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_item_income);
dao=AccountItemDao.getInstance();
itemListView=(ListView) findViewById(R.id.aii_item_list);
items=dao.findAllByExpense(0);
itemListView.setAdapter(itemAdapter);
itemListView.setOnItemClickListener(itemItemListener);
findViewById(R.id.aii_back).setOnClickListener(clickListener);
findViewById(R.id.aii_edit).setOnClickListener(clickListener);
intent=getIntent();
if(intent!=null){
String item=intent.getStringExtra(ITEM);
if(!TextUtils.isEmpty(item)){
boolean r=false;
for(int i=0;i<items.size();i++){
if(items.get(i).getItem().equals(item)){
seletectedItemPosition=i;
break;
}
}
}
}
itemListView.setSelection(seletectedItemPosition);
}
示例8: onCreateDialog
import android.widget.ListView; //导入方法依赖的package包/类
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater inflater = getActivity().getLayoutInflater();
View v = inflater.inflate(R.layout.sync_passphrase_types, null);
// Configure the passphrase type list
ListView list = (ListView) v.findViewById(R.id.passphrase_types);
Adapter adapter = createAdapter(getCurrentTypeFromArguments());
list.setAdapter(adapter);
list.setId(R.id.passphrase_type_list);
list.setOnItemClickListener(this);
list.setDividerHeight(0);
PassphraseType currentType = getCurrentTypeFromArguments();
list.setSelection(adapter.getPositionForType(currentType));
// Configure the hint to reset the passphrase settings
// Only show this hint if encryption has been set to use sync passphrase
if (currentType == PassphraseType.CUSTOM_PASSPHRASE) {
TextView instructionsView = (TextView) v.findViewById(R.id.reset_sync_text);
instructionsView.setVisibility(View.VISIBLE);
instructionsView.setMovementMethod(LinkMovementMethod.getInstance());
instructionsView.setText(getResetText());
}
// Create and return the dialog
return new AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme)
.setNegativeButton(R.string.cancel, this)
.setTitle(R.string.sync_passphrase_type_title)
.setView(v)
.create();
}
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:32,代码来源:PassphraseTypeDialogFragment.java
示例9: initializeListView
import android.widget.ListView; //导入方法依赖的package包/类
private void initializeListView(final int page, final List<T> data) {
final ListView listView = mListViewList.get(page);
final ColumnAdapter adapter;
if (mOnAdapterProvideList != null && mOnAdapterProvideList.get(page) != null) {
adapter = mOnAdapterProvideList.get(page).provideAdapter(this, data);
} else if (mOnAdapterProvide != null) {
adapter = mOnAdapterProvide.provideAdapter(this, data);
} else {
adapter = new SimpleColumnAdapter<>(data, MultiColumnsPicker.this);
}
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
for (T t : data) {
setChecked(t, false);
}
setChecked(data.get(position), true);
mOnSelected.onSelected(page, data.get(position));
adapter.notifyDataSetChanged();
}
});
for (int i = 0; i < data.size(); i++) {
if (isChecked(data.get(i))) {
listView.setSelection(i);
break;
}
}
}
示例10: scrollToBottomListItem
import android.widget.ListView; //导入方法依赖的package包/类
/**
* @Description 滑动到列表底部
*/
private void scrollToBottomListItem() {
logger.d("message_activity#scrollToBottomListItem");
// todo eric, why use the last one index + 2 can real scroll to the
// bottom?
ListView lv = lvPTR.getRefreshableView();
if (lv != null) {
lv.setSelection(adapter.getCount() + 1);
}
textView_new_msg_tip.setVisibility(View.GONE);
}
示例11: onCreate
import android.widget.ListView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_item_expense);
dao = AccountItemDao.getInstance();
EventBus.getDefault().register(this);
itemListView = (ListView) findViewById(R.id.aie_item_list);
subItemListView = (ListView) findViewById(R.id.aie_subitem_list);
items = dao.findAllByExpense(1);
subItems = dao.findAllSubItem();
inflater = LayoutInflater.from(mContext);
Log.w(TAG, "items.size=" + items.size() + ",subItems.size=" + subItems.size());
itemListView.setAdapter(itemAdapter);
itemListView.setOnItemClickListener(itemItemListener);
subItemListView.setAdapter(subAdapter);
// subItemListView.setOnItemClickListener(subItemItemListener);
findViewById(R.id.aie_back).setOnClickListener(clickListener);
findViewById(R.id.aie_edit).setOnClickListener(clickListener);
if (!TextUtils.isEmpty(item)) {
String is[] = item.split(",");
if (is.length == 2) {
boolean r = false;
for (int i = 0; i < subItems.size(); i++) {
if (subItems.get(i).getName().equals(is[1])) {
for (int j = 0; j < items.size(); j++) {
if (items.get(j).getId() == subItems.get(i).getItemid()) {
if (items.get(j).getItem().equals(is[0])) {
selectedSubItemId = subItems.get(i).getId();
seletectedItemPosition = j;
r = true;
break;
}
}
}
if (r)
break;
}
}
}
}
setShowSubItems(items.get(seletectedItemPosition).getId());
itemListView.setSelection(seletectedItemPosition);
}
示例12: onCreate
import android.widget.ListView; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_item_expense);
dao = AccountItemDao.getInstance();
itemListView = (ListView) findViewById(R.id.aie_item_list);
subItemListView = (ListView) findViewById(R.id.aie_subitem_list);
items = dao.findAllByExpense(1);
subItems = dao.findAllSubItem();
Log.w(TAG, "items.size=" + items.size() + ",subItems.size=" + subItems.size());
itemListView.setAdapter(itemAdapter);
itemListView.setOnItemClickListener(itemItemListener);
subItemListView.setAdapter(subAdapter);
subItemListView.setOnItemClickListener(subItemItemListener);
findViewById(R.id.aie_back).setOnClickListener(clickListener);
findViewById(R.id.aie_edit).setOnClickListener(clickListener);
intent = getIntent();
if (intent != null) {
String item = intent.getStringExtra(ITEM);
Log.w(TAG, "item=" + item);
if (!TextUtils.isEmpty(item)) {
String is[] = item.split(",");
if (is.length == 2) {
boolean r = false;
for (int i = 0; i < subItems.size(); i++) {
if (subItems.get(i).getName().equals(is[1])) {
for (int j = 0; j < items.size(); j++) {
if (items.get(j).getId() == subItems.get(i).getItemid()) {
if (items.get(j).getItem().equals(is[0])) {
selectedSubItemId = subItems.get(i).getId();
seletectedItemPosition = j;
r = true;
break;
}
}
}
if (r)
break;
}
}
}
}
}
setShowSubItems(items.get(seletectedItemPosition).getId());
itemListView.setSelection(seletectedItemPosition);
}