数据库建立
package models;
import java.util.Date;
import com.example.account.AddEvent;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import android.widget.Toast;
import db.DBHelper;
public abstract class TradeClass {
private int _id;
private float money;
private String time;
private String packageType;
private String mark;
private DBHelper dbhelper;
private SQLiteDatabase db;
private String tablename;
public TradeClass(int id,float money,String time2,String mark,String packageType,Context context){
this._id=id;
this.mark=mark;
this.money=money;
this.packageType=packageType;
this.time=time2;
dbhelper=new DBHelper(context);
}
//_id INTEGER PRIMARY KEY,pocketType varchar(20),addTime date,money float,mark TEXT
public void trade_add(){
db=dbhelper.getWritableDatabase();
try
{
ContentValues localContentValues = new ContentValues();
//localContentValues.put("_id", GetMaxid());
localContentValues.put("pocketType", this.packageType);
localContentValues.put("addTime", this.time);
localContentValues.put("money", this.money);
localContentValues.put("mark", this.mark);
db.insert(tablename, null, localContentValues);
db.close();
return;
}
catch (Exception localException)
{
Log.v("id", "add consume error");
}
}
public void trade_modify(){
}
public int trade_delect(int id){
db=dbhelper.getWritableDatabase();
try
{
db.delete(tablename, "_id="+id, null);
return 1;
}
catch (Exception localException)
{
return 0;
}
}
private int GetMaxid(){
db=dbhelper.getWritableDatabase();
try{
Cursor cu=db.rawQuery("select max(_id) from "+this.tablename, null);
while(cu.moveToLast()){
return cu.getInt(0);
}
cu.close();
db.close();
}catch(Exception localExceptio){
}
return 0;
}
public float getMoney()
{
return this.money;
}
public String gettime()
{
return this.time;
}
public int getId()
{
return this._id;
}
public String getPocketType()
{
return this.packageType;
}
public void setMoney(float paramFloat)
{
this.money = paramFloat;
}
public void settime(String paramDate)
{
this.time = paramDate;
}
public void setPocketId(int paramInt)
{
this._id = paramInt;
}
public void setPocketType(String paramString)
{
this.packageType = paramString;
}
public String getmark()
{
return this.mark;
}
public void setmark(String mark)
{
this.mark = mark;
}
public void settablename(String tablename)
{
this.tablename = tablename;
}
}
布局设计
布局代码
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:id="@+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView android:id="@+id/tishi1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3.0dip"
android:text="操作提示:" />
<TextView android:id="@+id/tishi2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第一步:输入新消费的金额"
android:layout_below="@+id/tishi1"
android:layout_alignLeft="@+id/tishi1" />
<TextView android:id="@+id/tishi3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第二步:选择新消费的类型"
android:layout_below="@+id/tishi2"
android:layout_alignLeft="@+id/tishi2" />
<TextView android:id="@+id/tishi4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第三步:点击添加账单按钮,添加成功"
android:layout_below="@+id/tishi3"
android:layout_alignLeft="@+id/tishi3" />
<TextView android:textSize="18.0dip"
android:id="@+id/addDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15.0dip"
android:text="点击选择日期"
android:layout_below="@+id/tishi4"
android:layout_centerHorizontal="true" />
<TextView android:textSize="18.0dip"
android:id="@+id/tishi5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10.0dip"
android:layout_marginTop="12.0dip"
android:text="消费金额:"
android:layout_below="@+id/addDate" />
<EditText android:id="@+id/money"
android:layout_width="150.0dip"
android:layout_height="wrap_content"
android:layout_marginTop="-7.0dip"
android:layout_toRightOf="@+id/tishi5"
android:layout_alignTop="@+id/tishi5"
android:inputType="numberDecimal" />
<TextView android:textSize="18.0dip"
android:id="@+id/tishi6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10.0dip"
android:layout_marginTop="20.0dip"
android:text="消费类型:"
android:layout_below="@+id/tishi5" />
<Spinner android:id="@+id/type"
android:layout_width="150.0dip"
android:layout_height="wrap_content"
android:layout_marginLeft="0.0dip"
android:layout_marginTop="-7.0dip"
android:layout_toRightOf="@+id/tishi6"
android:layout_alignTop="@+id/tishi6" />
<Button android:id="@+id/addButton"
android:background="@drawable/tianjia"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10.0dip"
android:layout_toRightOf="@+id/tishi6"
android:layout_below="@+id/type"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</ScrollView>