Android记事本listview不显示内容

调试的错误只有getSlotFromBufferLocked: unknown buffer: 0xa068fd80
SQL数据能正常写入

Adapter.java
package com.example.note;

import android.annotation.SuppressLint;
import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class Adapter extends BaseAdapter{

private Context context;
private Cursor cursor;
private LinearLayout layout; 

public Adapter(Context context,Cursor cursor) {
        this.context = context;
        this.cursor = cursor;
}

public int getCount() {
    return cursor.getCount();
}

@Override
public Object getItem(int position) {
    return cursor.getPosition();
}

@Override
public long getItemId(int position) {
    return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = LayoutInflater.from(context); //加载视图的权限
    layout = (LinearLayout) inflater.inflate(R.layout.cell, null);
    TextView contenttv = (TextView) layout.findViewById(R.id.list_content);
    TextView timetv = (TextView) layout.findViewById(R.id.list_time);
    ImageView imgiv = (ImageView) layout.findViewById(R.id.list_img);
    ImageView videoiv = (ImageView) layout.findViewById(R.id.list_video);//截取视频中第一张图进行显示
    cursor.moveToPosition(position);//查询
    String content = cursor.getString(cursor.getColumnIndex("content"));//查询的内容
    String time = cursor.getString(cursor.getColumnIndex("time"));
    contenttv.setText(content);
    timetv.setText(time);
    System.out.println("返回成功");
    return layout;

}

}

MainActivity.java
 package com.example.note;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;

public class MainActivity extends Activity implements OnClickListener{

private Button textbtn,imgbtn,videobtn;
private ListView lv;
private Intent i;
private Adapter adapter;
private NotesDB notesDB;
private SQLiteDatabase dbReader;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initView();
}

public void initView(){
    lv = (ListView) findViewById(R.id.list);
    textbtn = (Button) findViewById(R.id.text);
    imgbtn = (Button) findViewById(R.id.img);
    videobtn = (Button) findViewById(R.id.video);
    textbtn.setOnClickListener(this);
    imgbtn.setOnClickListener(this);
    videobtn.setOnClickListener(this);
    notesDB = new NotesDB(this);
    dbReader = notesDB.getReadableDatabase();
}

@Override
public void onClick(View v) {
    i = new Intent(this,add.class);
    switch (v.getId()) {
    case R.id.text:
        i.putExtra("flag","1");
        startActivity(i);
        break;

    case R.id.img:
        i.putExtra("flag","2");
        startActivity(i);
        break;

    case R.id.video:
        i.putExtra("flag","3");
        startActivity(i);
        break;
    }

}
public void selectDB(){
    Cursor cursor = dbReader.query(NotesDB.TABLE_NAME, null, null, null
            , null, null, null);
    adapter = new Adapter(this,cursor);
    lv.setAdapter(adapter);
}
@Override
protected void onResume() {
    super.onResume();
    selectDB();
}

}

3个回答

http://blog.csdn.net/baisemaque/article/details/50562329 看下这篇博客,简单解释了下,貌似也没得到解决

怀疑和这个有关。
你的Cursor查完还是封装到集合中去展示,这样Cursor和sql都没有关闭 耗资源的

cursor.getPosition()

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问