使用DataBase(Sqlite)中的自定义简单光标适配器列出视图“未处理的事件循环异常”

时间:2012-05-26 12:10:31

标签: android listview simplecursoradapter sqlite

我为Listview尝试了一个Custom Simple Cursor适配器。我从数据库中获取数据并尝试显示我的列表视图但是我有一些例外。如果你帮助我,我会非常感谢。这是代码:

public class cursorDeneme extends ListActivity{
Cursor c ;
String sutunlar[]  = new String[]{"name"};
int to[] = new int[]{R.id.name_entry};
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cursorden);
DB_E db = new DB_E(this);// database class

try {
    db.openReadable();

    c=db.veriAlCursor();// gets Cursor from database

    mySimpleCursorAdapter adapter = new mySimpleCursorAdapter(this, R.layout.cursorden, c, sutunlar, to);

    db.close();
    this.setListAdapter(adapter);


} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}}

这是数据库类:

 public class DB_E {
    public static final String KEY_ROWID ="id";
public static final String KEY_WORK_OUT ="workout"; //Hangi workout
public static final String KEY_NAME ="name";
public static final String KEY_REP ="rep";
public static final String KEY_WEIGHT ="weight";
    public Cursor veriAlCursor(){ //get datas

    Cursor c = ourDataBase.query(DATABASE_TABLE, sutunlar, null, null, null, null, null);

    return c;
}
public Cursor veriAlCursor(String workout){ //get datas

workout ="'%"+workout+"%'";
    Cursor c = ourDataBase.query(DATABASE_TABLE, sutunlar, KEY_WORK_OUT+" LIKE "+workout, null, null, null, null);

    return c;
}

mySimpleCustomAdapter:

public class mySimpleCursorAdapter extends SimpleCursorAdapter {
Cursor c;
Context context;
Activity activity;
cursorDeneme cursorD ;
public mySimpleCursorAdapter(Context context, int layout, Cursor c,
        String[] from, int[] to) {
    super(context, layout, c, from, to);

    this.c=c;
    this.activity=(Activity)context;
    this.context=context;
    this.cursorD =(cursorDeneme)context;
}

@Override
public View getView(int position , View convertView , ViewGroup parent){

    if(convertView == null)
    convertView.inflate(context, R.layout.liste, null);

    View row=convertView;

    c.moveToPosition(position);
    int iName =c.getColumnIndex("name");
    TextView name =(TextView)convertView.findViewById(R.id.name_entry);
    name.setText(c.getString(iName));
    return (row);
}

和Xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:orientation="vertical"
android:background="#848484" >
<LinearLayout 
    android:id="@+id/linear1"
    android:layout_width="240dp"
    android:layout_height="350dp"
    android:background="#CEF6E3"
    android:layout_marginLeft="40dp"
    android:layout_marginTop="20dp"
      android:layout_marginRight="20dp"
      android:layout_marginBottom="20dp"
    >
    <ListView 
        android:id="@+id/listView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#151515"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        ></ListView>
      </LinearLayout>
 </LinearLayout>

错误日志:未处理的事件循环异常             无效的首选项页面路径:XML语法             ... 感谢。

0 个答案:

没有答案