我想在android中创建一个循环列表视图(滚动到最后一个元素后它开始显示第一个元素并继续)但我在网络上没有找到任何帮助。我只想知道它们在 Android 中的任何默认属性/组件是否支持循环列表视图,或者我需要通过为其添加一些逻辑来创建自定义列表视图。
问问题
1621 次
2 回答
3
检查此循环列表适配器
于 2012-11-21T06:09:37.673 回答
0
如果使用 LoadersCallbacks 我已经创建了 MyCircularCursor 类,它像这样包装典型的光标:
@Override
public void onLoadFinished(Loader<Cursor> pCursorLoader, Cursor pCursor) {
mItemListAdapter.swapCursor(new MyCircularCursor(pCursor));
}
装饰器类代码在这里:
/**
* {@link MyCircularCursor}<br/>
* <br/>
* @author Vilius Kraujutis
* @since 31 Jan 2013 02:09:48
*
*/
public class MyCircularCursor implements Cursor {
private Cursor mCursor;
/**
* @param pCursor
*/
public MyCircularCursor(Cursor pCursor) {
mCursor = pCursor;
}
/*
* (non-Javadoc)
* @see android.database.Cursor#getCount()
*/
@Override
public int getCount() {
return mCursor.getCount() == 0 ? 0 : Integer.MAX_VALUE;
}
/*
* (non-Javadoc)
* @see android.database.Cursor#getPosition()
*/
@Override
public int getPosition() {
return mCursor.getPosition();
}
/*
* (non-Javadoc)
* @see android.database.Cursor#move(int)
*/
@Override
public boolean move(int pOffset) {
return mCursor.move(pOffset);
}
/*
* (non-Javadoc)
* @see android.database.Cursor#moveToPosition(int)
*/
@Override
public boolean moveToPosition(int pPosition) {
int position = MathUtils.mod(pPosition, mCursor.getCount());
return mCursor.moveToPosition(position);
}
/*
* (non-Javadoc)
* @see android.database.Cursor#moveToFirst()
*/
@Override
public boolean moveToFirst() {
return mCursor.moveToFirst();
}
/*
* (non-Javadoc)
* @see android.database.Cursor#moveToLast()
*/
@Override
public boolean moveToLast() {
return mCursor.moveToLast();
}
/*
* (non-Javadoc)
* @see android.database.Cursor#moveToNext()
*/
@Override
public boolean moveToNext() {
if (mCursor.isLast()) {
mCursor.moveToFirst();
return true;
} else {
return mCursor.moveToNext();
}
// return mCursor.moveToNext();
}
/*
* (non-Javadoc)
* @see android.database.Cursor#moveToPrevious()
*/
@Override
public boolean moveToPrevious() {
if (mCursor.isFirst()) {
mCursor.moveToLast();
return true;
} else {
return mCursor.moveToPrevious();
}
// return mCursor.moveToPrevious();
}
/*
* (non-Javadoc)
* @see android.database.Cursor#isFirst()
*/
@Override
public boolean isFirst() {
// return mCursor.isFirst();
return false;
}
/*
* (non-Javadoc)
* @see android.database.Cursor#isLast()
*/
@Override
public boolean isLast() {
return false;
// return mCursor.isLast();
}
/*
* (non-Javadoc)
* @see android.database.Cursor#isBeforeFirst()
*/
@Override
public boolean isBeforeFirst() {
return false;
// return mCursor.isBeforeFirst();
}
/*
* (non-Javadoc)
* @see android.database.Cursor#isAfterLast()
*/
@Override
public boolean isAfterLast() {
return false;
// return mCursor.isAfterLast();
}
/*
* (non-Javadoc)
* @see android.database.Cursor#getColumnIndex(java.lang.String)
*/
@Override
public int getColumnIndex(String pColumnName) {
return mCursor.getColumnIndex(pColumnName);
}
/*
* (non-Javadoc)
* @see android.database.Cursor#getColumnIndexOrThrow(java.lang.String)
*/
@Override
public int getColumnIndexOrThrow(String pColumnName) throws IllegalArgumentException {
return mCursor.getColumnIndexOrThrow(pColumnName);
}
/*
* (non-Javadoc)
* @see android.database.Cursor#getColumnName(int)
*/
@Override
public String getColumnName(int pColumnIndex) {
return mCursor.getColumnName(pColumnIndex);
}
/*
* (non-Javadoc)
* @see android.database.Cursor#getColumnNames()
*/
@Override
public String[] getColumnNames() {
return mCursor.getColumnNames();
}
/*
* (non-Javadoc)
* @see android.database.Cursor#getColumnCount()
*/
@Override
public int getColumnCount() {
return mCursor.getColumnCount();
}
/*
* (non-Javadoc)
* @see android.database.Cursor#getBlob(int)
*/
@Override
public byte[] getBlob(int pColumnIndex) {
return mCursor.getBlob(pColumnIndex);
}
/*
* (non-Javadoc)
* @see android.database.Cursor#getString(int)
*/
@Override
public String getString(int pColumnIndex) {
return mCursor.getString(pColumnIndex);
}
/*
* (non-Javadoc)
* @see android.database.Cursor#getShort(int)
*/
@Override
public short getShort(int pColumnIndex) {
return mCursor.getShort(pColumnIndex);
}
/*
* (non-Javadoc)
* @see android.database.Cursor#getInt(int)
*/
@Override
public int getInt(int pColumnIndex) {
return mCursor.getInt(pColumnIndex);
}
/*
* (non-Javadoc)
* @see android.database.Cursor#getLong(int)
*/
@Override
public long getLong(int pColumnIndex) {
return mCursor.getLong(pColumnIndex);
}
/*
* (non-Javadoc)
* @see android.database.Cursor#getFloat(int)
*/
@Override
public float getFloat(int pColumnIndex) {
return mCursor.getFloat(pColumnIndex);
}
/*
* (non-Javadoc)
* @see android.database.Cursor#getDouble(int)
*/
@Override
public double getDouble(int pColumnIndex) {
return mCursor.getDouble(pColumnIndex);
}
/*
* (non-Javadoc)
* @see android.database.Cursor#getType(int)
*/
@Override
public int getType(int pColumnIndex) {
// return mCursor.getType(pColumnIndex);
return 0;
}
/*
* (non-Javadoc)
* @see android.database.Cursor#isNull(int)
*/
@Override
public boolean isNull(int pColumnIndex) {
return mCursor.isNull(pColumnIndex);
}
/*
* (non-Javadoc)
* @see android.database.Cursor#deactivate()
*/
@Override
public void deactivate() {
mCursor.deactivate();
}
/*
* (non-Javadoc)
* @see android.database.Cursor#requery()
*/
@Override
@Deprecated
public boolean requery() {
return mCursor.requery();
}
/*
* (non-Javadoc)
* @see android.database.Cursor#close()
*/
@Override
public void close() {
mCursor.close();
}
/*
* (non-Javadoc)
* @see android.database.Cursor#isClosed()
*/
@Override
public boolean isClosed() {
return mCursor.isClosed();
}
/*
* (non-Javadoc)
* @see android.database.Cursor#registerContentObserver(android.database.ContentObserver)
*/
@Override
public void registerContentObserver(ContentObserver pObserver) {
mCursor.registerContentObserver(pObserver);
}
/*
* (non-Javadoc)
* @see android.database.Cursor#unregisterContentObserver(android.database.ContentObserver)
*/
@Override
public void unregisterContentObserver(ContentObserver pObserver) {
mCursor.unregisterContentObserver(pObserver);
}
/*
* (non-Javadoc)
* @see android.database.Cursor#registerDataSetObserver(android.database.DataSetObserver)
*/
@Override
public void registerDataSetObserver(DataSetObserver pObserver) {
mCursor.registerDataSetObserver(pObserver);
}
/*
* (non-Javadoc)
* @see android.database.Cursor#unregisterDataSetObserver(android.database.DataSetObserver)
*/
@Override
public void unregisterDataSetObserver(DataSetObserver pObserver) {
mCursor.unregisterDataSetObserver(pObserver);
}
/*
* (non-Javadoc)
* @see android.database.Cursor#setNotificationUri(android.content.ContentResolver,
* android.net.Uri)
*/
@Override
public void setNotificationUri(ContentResolver pCr, Uri pUri) {
mCursor.setNotificationUri(pCr, pUri);
}
/*
* (non-Javadoc)
* @see android.database.Cursor#getWantsAllOnMoveCalls()
*/
@Override
public boolean getWantsAllOnMoveCalls() {
return mCursor.getWantsAllOnMoveCalls();
}
/*
* (non-Javadoc)
* @see android.database.Cursor#getExtras()
*/
@Override
public Bundle getExtras() {
return mCursor.getExtras();
}
/*
* (non-Javadoc)
* @see android.database.Cursor#respond(android.os.Bundle)
*/
@Override
public Bundle respond(Bundle pExtras) {
return mCursor.respond(pExtras);
}
/*
* (non-Javadoc)
* @see android.database.Cursor#copyStringToBuffer(int, android.database.CharArrayBuffer)
*/
@Override
public void copyStringToBuffer(int pColumnIndex, CharArrayBuffer pBuffer) {
mCursor.copyStringToBuffer(pColumnIndex, pBuffer);
}
}
于 2013-01-31T00:17:26.460 回答