package com.vidhi.grietportal;
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class Update extends Activity {
Button b1,b2,b3;
EditText e1,e2,e3;
AttendanceDataBaseAdapter adb;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.update);
adb= new AttendanceDataBaseAdapter(this);
adb=adb.open();
b1=(Button)findViewById(R.id.insert);
b2=(Button)findViewById(R.id.update);
b3=(Button)findViewById(R.id.show);
e1=(EditText)findViewById(R.id.entryforroll);
e2=(EditText)findViewById(R.id.entryforname);
e3=(EditText)findViewById(R.id.entryforpercentage);
final String roll=e1.getText().toString();
final String name=e2.getText().toString();
final String percent=e3.getText().toString();
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
adb.insertEntry(roll,name,percent);
}
});
b2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
adb.updateEntry(roll,name,percent);
}
});
b3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
});
}
}
单击第三个按钮时,我希望它以漂亮的列表或表格格式显示“出席”表格的内容。我对android中的数据库完全陌生,并且难以编写代码!有人能帮助我吗!
这是我的适配器类
package com.vidhi.grietportal;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
public class AttendanceDataBaseAdapter
{
public final String DATABASE_NAME="griet.db";
static final int DATABASE_VERSION=2;
static final int NAME_COLUMN=1;
public SQLiteDatabase db;
private final Context context;
private DataBaseHelper dbhelper;
public AttendanceDataBaseAdapter(Context _context)
{
context=_context;
dbhelper=new DataBaseHelper(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public AttendanceDataBaseAdapter open() throws SQLException
{
db=dbhelper.getWritableDatabase();
return this;
}
public void close()
{
db.close();
}
public SQLiteDatabase getDatabaseInstance()
{
return db;
}
public void insertEntry(String roll,String name,String percent)
{
ContentValues newcontent=new ContentValues();
newcontent.put("ROLLNO",roll);
newcontent.put("STUNAME", name);
newcontent.put("PERCENTAGE",percent);
db.insert("ATTENDANCE",null, newcontent);
}
public void updateEntry(String roll,String name,String percent)
{
ContentValues newupdate=new ContentValues();
newupdate.put("ROLLNO", roll);
newupdate.put("STUNAME",name);
newupdate.put("PERCENTAGE", percent);
String where="ROLLNO=?";
db.update("ATTENDANCE", newupdate, where, new String[] {roll});
}
public Cursor show() {
}
}