下面列出了android.widget.ListView#INVALID_POSITION 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
infoListAdapter.swapCursor(cursor);
if (mPosition != ListView.INVALID_POSITION) {
listView.smoothScrollToPosition(mPosition);
}
try {
TextView info = (TextView) rootView.findViewById(R.id.empty);
if (infoListAdapter.getCount() == 0) {
info.setText(R.string.list_empty_info);
info.setVisibility(View.VISIBLE);
} else {
info.setVisibility(View.GONE);
}
} catch (Exception ignored) {
}
}
protected void siteChanged(RadioGroup group, int checkedId) {
if (checkedId == -1) {
return;
}
RadioButton button = (RadioButton) group.findViewById(checkedId);
Site site = (Site) button.getTag();
if (site != null) {
App.setSiteUrl(site.getUrl());
}
if (site == null) {
group.clearCheck();
openSettingsActivity();
} else if (!site.getUrl().equals(mCurrentSiteUrl)) { // TODO 第一次启动 加载上次查看的url。
mDrawerPosition = ListView.INVALID_POSITION;
mCurrentSite = site;
mCurrentSiteUrl = site.getUrl();
PrefsUtils.setCurrentSiteUrl(mCurrentSiteUrl);
App.setLogin(false);
clearDatabase();
// 登陆完成后,再加载其他信息
loadUserInfo(site, false);
} else {
setupUserInfo(mUser);
}
getActionBar().setSubtitle(mCurrentSiteUrl);
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (mActivatedPosition != ListView.INVALID_POSITION) {
// Serialize and persist the activated item position.
outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
}
}
private void setActivatedPosition(int position) {
if (position == ListView.INVALID_POSITION) {
getListView().setItemChecked(mActivatedPosition, false);
} else {
getListView().setItemChecked(position, true);
}
mActivatedPosition = position;
}
private void resetSwipeState() {
if (mVelocityTracker != null) {
mVelocityTracker.recycle();
}
mVelocityTracker = null;
mDownX = 0;
mDownY = 0;
mDownView = null;
mDownPosition = ListView.INVALID_POSITION;
mSwiping = false;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (mActivatedPosition != ListView.INVALID_POSITION) {
// Serialize and persist the activated item position.
outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
}
}
public void onItemClick(AdapterView<?> arg0, View view, int posicion, long id) {
if (posicion == ListView.INVALID_POSITION)
return;
Restaurante restaurante = listaRestaurantes.get(posicion);
Intent i = new Intent(this, Mapa.class);
i.putExtra("latitud", restaurante.getLatitud());
i.putExtra("longitud", restaurante.getLongitud());
i.putExtra("nombre", restaurante.getNombre());
startActivity(i);
}
@Override
public void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);
if (mActivatedPosition != ListView.INVALID_POSITION)
outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
if (mAlwaysUseOption) {
final int checkedPos = mListView.getCheckedItemPosition();
final boolean enabled = checkedPos != ListView.INVALID_POSITION;
mLastSelected = checkedPos;
mAlwaysButton.setEnabled(enabled);
mOnceButton.setEnabled(enabled);
if (enabled) {
mListView.setSelection(checkedPos);
}
}
}
private void setActivatedPosition(int position) {
// //Log.d(TAG, "ListFragment SETACTIVATED");
if (position == ListView.INVALID_POSITION) {
mListView.setItemChecked(mActivatedPosition, false);
} else {
mListView.setItemChecked(position, true);
}
mActivatedPosition = position;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (mActivatedPosition != ListView.INVALID_POSITION) {
// Serialize and persist the activated item position.
outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
}
}
public void onItemClick(AdapterView<?> arg0, View view, int posicion, long id) {
if (posicion == ListView.INVALID_POSITION)
return;
Restaurante restaurante = listaRestaurantes.get(posicion);
Intent i = new Intent(this, Mapa.class);
i.putExtra("latitud", restaurante.getLatitud());
i.putExtra("longitud", restaurante.getLongitud());
i.putExtra("nombre", restaurante.getNombre());
startActivity(i);
}
@Override
public void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);
if (mActivatedPosition != ListView.INVALID_POSITION) {
// Serialize and persist the activated item position.
outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
}
}
private void setActivatedPosition(int position) {
if (position == ListView.INVALID_POSITION) {
getListView().setItemChecked(mActivatedPosition, false);
} else {
getListView().setItemChecked(position, true);
}
mActivatedPosition = position;
}
private void setActivatedPosition(int position) {
if (position == ListView.INVALID_POSITION) {
getListView().setItemChecked(mActivatedPosition, false);
} else {
getListView().setItemChecked(position, true);
}
mActivatedPosition = position;
}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putParcelableArrayList("infoList", infoList);
if (mPosition != ListView.INVALID_POSITION) {
outState.putInt(SELECTED_KEY, mPosition);
}
super.onSaveInstanceState(outState);
}
private ViewHolder getViewHolderByView(View view) {
try {
final int position = listView.getPositionForView(view);
if (position == ListView.INVALID_POSITION) {
return null;
}
return getViewHolderByView(position);
} catch (NullPointerException e) {
}
return null;
}
/**
* Notifies onClickBackView
*
* @param position back item clicked
*/
protected void onClickBackView(int position) {
if (swipeListViewListener != null && position != ListView.INVALID_POSITION) {
swipeListViewListener.onClickBackView(position);
}
}
protected int changeSwipeMode(int position) {
if (swipeListViewListener != null && position != ListView.INVALID_POSITION) {
return swipeListViewListener.onChangeSwipeMode(position);
}
return SWIPE_MODE_DEFAULT;
}
/**
* Start close item
*
* @param position list item
* @param right na
*/
protected void onStartClose(int position, boolean right) {
if (swipeListViewListener != null && position != ListView.INVALID_POSITION) {
swipeListViewListener.onStartClose(position, right);
}
}