为了账号安全,请及时绑定邮箱和手机立即绑定

源码吗,希望贡献一下

后续能不断增加课程。能有实际应用,有代码参考更好了。

正在回答

1 回答

package com.example.mytest0001;

import java.io.File;

import android.app.Activity;

import android.content.Context;

import android.database.Cursor;

import android.database.sqlite.SQLiteDatabase;

import android.os.Bundle;

import android.os.Environment;

import android.view.View;

import android.view.ViewGroup;

import android.widget.CursorAdapter;

import android.widget.ListView;

import android.widget.TextView;

public class CursorAdapterActivity extends Activity {

private ListView lv;

private SQLiteDatabase db;

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

setContentView(R.layout.cursor_adapter_activity);

lv = (ListView) findViewById(R.id.lv);

db = SQLiteDatabase.openDatabase(

Environment.getExternalStorageDirectory() + File.separator

+ "info.db", null, SQLiteDatabase.OPEN_READONLY);

Cursor cursor=db.rawQuery("select * from "+Constant.TABLE_NAME, null);

MyCursorAdapter adapter =new MyCursorAdapter(this, cursor, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);

        lv.setAdapter(adapter);

}

class MyCursorAdapter extends CursorAdapter{

public MyCursorAdapter(Context context, Cursor c, int flags) {

super(context, c, flags);

// TODO Auto-generated constructor stub

}


/**

*/

@Override

public View newView(Context arg0, Cursor arg1, ViewGroup arg2) {

// TODO Auto-generated method stub

return getLayoutInflater().inflate(R.layout.layout1,null );

}

@Override

public void bindView(View arg0, Context arg1, Cursor arg2) {

TextView tv_id= (TextView) arg0.findViewById(R.id.tv_id);

TextView tv_name= (TextView) arg0.findViewById(R.id.tv_name);

TextView tv_age= (TextView) arg0.findViewById(R.id.tv_age);

int _id=arg2.getInt(arg2.getColumnIndex(Constant._ID));

String name=arg2.getString(arg2.getColumnIndex(Constant.NAME));

int age=arg2.getInt(arg2.getColumnIndex(Constant.AGE));

tv_id.setText(_id +"");

tv_name.setText(name);

tv_age.setText(age +"");

}

 

}

}


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

源码吗,希望贡献一下

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信