我有这个非常奇怪的问题,我使用simplecursoradapter创建了一个listview来显示数据库中的显示项目,我有25行,而lisview只显示10行来填充屏幕而不能向下滚动。
我被困在这里4个星期,PLZ帮助
活动显示listview
channellist = (ListView) findViewById(R.id.Channel);
mDB = new ChannelDB(this);
String[] columns = {mDB.KEY_ID, mDB.KEY_POSTER, mDB.KEY_CHANNEL, mDB.KEY_PATH, mDB.KEY_DBLINK};
String table = mDB.channelS_TABLE;
c = mDB.getHandle().query(table, columns, null, null, null, null, null);
startManagingCursor(c);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.channelview,
c,
new String[] {mDB.KEY_POSTER, mDB.KEY_CHANNEL, mDB.KEY_DBLINK},
new int[] {R.id.poster, R.id.channel, R.id.douban});
adapter.setViewBinder(new ChannelViewBinder(this));
channellist.setAdapter(adapter);
我的数据库表和密钥
private static final String DATABASE_NAME = "channelDB";
private static final int DATABASE_VERSION = 1;
public static final String channelS_TABLE = "channels";
private static final String CREATE_channelS_TABLE = "create table "+channelS_TABLE+" ("
+KEY_ID+" integer primary key autoincrement, "
+KEY_POSTER+" blob not null, "
+KEY_CHANNEL+" text not null unique, "
+KEY_DBLINK+" integer not null, "
+KEY_PATH+" integer not null);";
最奇怪的一点是我每次都从logcat得到这个
12-06 12:07:13.299: DEBUG/skia(1009): --- SkImageDecoder::Factory returned null
表示数据库中的BitArray返回null
但是当我将LIMIT设置为查询时,显示另一页并且图片没问题,这意味着所有图像都可以从数据库转移到imageview,所以我不明白,为什么会发生这种情况?
我只是尝试从查询中删除图像,列表视图仍然在一个页面中,无法滚动
channelViewVinder.java
public class ChannelViewBinder implements SimpleCursorAdapter.ViewBinder {
private ChannelDB mDB;
private Context mContext = null;
public ChannelViewBinder(Context context) {
mContext = context;
}
public boolean setViewValue(View view, final Cursor cursor, int columnIndex) {
mDB = new ChannelDB(mContext);
if(view instanceof ImageView) {
ImageView iv = (ImageView) view;
byte[] img = cursor.getBlob(columnIndex);
iv.setImageBitmap(BitmapFactory.decodeByteArray(img, 0, img.length));
return true;
}
if(view instanceof ImageButton) {
ImageButton ib = (ImageButton) view;
ib.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String[] columns = {mDB.KEY_ID, mDB.KEY_POSTER, mDB.KEY_CHANNEL, mDB.KEY_PATH, mDB.KEY_DBLINK};
String table = mDB.channelS_TABLE;
Cursor c = mDB.getHandle().query(table, columns, null, null, null, null, null);
String dblink = c.getString(cursor.getColumnIndex(mDB.KEY_DBLINK));
Log.i("ChannelViewBinder", "path = " + dblink);
Intent intent = new Intent();
intent.setClass(mContext, Doubanframe.class);
Bundle bunde = new Bundle();
bunde.putString("dblink",dblink);
intent.putExtras(bunde);
mContext.startActivity(intent);
}
});
}
return false;
}
}
这就是我插入条目的方式
Bitmap sherlock = BitmapFactory.decodeResource(getResources(), R.drawable.sherlock);
mDB.createchannelEntry(new ChannelPoster(sherlock, "xxxx" ,"http://appkon.com/hdtvs/channel/bigbang1.xml" ,"http://movie.douban.com/subject/5372374/" ));
这是频道投标
public class ChannelPoster {
private Bitmap poster;
private String channel;
private String path;
private String dblink;
public ChannelPoster(Bitmap pi, String c, String p, String d) {
poster = pi;
channel = c;
path = p;
dblink = d;
}
public Bitmap getPoster() { return poster; }
public String getChannel() { return channel; }
public String getPath() { return path; }
public String getDBlink() { return dblink; }
}