标签:
今天做了什么?
预期值设置界面
源代码:
1 package com.example.grouptext02; 2 3 4 import android.app.Activity; 5 import android.content.Intent; 6 import android.database.Cursor; 7 import android.database.sqlite.SQLiteDatabase; 8 import android.os.Bundle; 9 import android.util.Log; 10 import android.view.View; 11 import android.view.View.OnClickListener; 12 import android.widget.Button; 13 import android.widget.EditText; 14 import android.widget.Toast; 15 16 public class Set extends Activity { 17 18 int sum_money = 0; 19 SQLiteDatabase db; 20 @Override 21 protected void onCreate(Bundle savedInstanceState) { 22 super.onCreate(savedInstanceState); 23 setContentView(R.layout.set); 24 Log.v("TAG","王大思的标记set.1"); 25 //final EditText et1 =(EditText) findViewById(R.id.income_in); 26 27 final EditText et2 =(EditText) findViewById(R.id.out_in);//输入的预期值 28 Log.v("TAG","王大思的标记set.2"); 29 30 //通过数据库获得输入所有金额的总数 31 DataHelper helper = new DataHelper(getBaseContext()); 32 db = helper.getWritableDatabase(); 33 Cursor cursor = db.query(DataHelper.TABLENAME, new String[]{DataHelper.MONEY}, null, null,null,null,null); 34 Log.v("TAG","王大思的标记set.3"); 35 cursor.moveToFirst(); 36 37 String sql = "DELETE FROM " + DataHelper.TABLENAME +";"; 38 db.execSQL(sql); 39 40 for(int i = 0;i < cursor.getCount();i++) 41 { 42 sum_money += Integer.parseInt(cursor.getString(i)); 43 } 44 cursor.close(); 45 Log.v("TAG","王大思的标记set.4"); 46 47 Button Button = (Button) findViewById(R.id.button1); 48 Log.v("TAG","王大思的标记set.5"); 49 Button.setOnClickListener(new OnClickListener() 50 { 51 public void onClick(View arg0) 52 { 53 Log.v("TAG","王大思的标记set.5.1"); 54 int money =Integer.parseInt(et2.getText().toString()); 55 Log.v("TAG","王大思的标记set.5.2"); 56 //和输入的预期值进行比较 57 if(sum_money>money) 58 { 59 Log.v("TAG","王大思的标记set.6"); 60 //如果money<总数值那么进行警报 61 Toast.makeText(getBaseContext(), "花费已经超出预期", Toast.LENGTH_LONG).show(); 62 } 63 Intent i = new Intent(Set.this,Mainpage.class); 64 startActivity(i);//跳转 65 } 66 }); 67 68 } 69 70 }
功能实现:1.从数据库中获取所有金额并且相加,得到总和
2.输入预期值
3.进行对输入预期值还有总和的比较,如果超过预期值就进行报警
明天准备做什么?
设置界面布局文件
遇到的困难?
本部分没有遇到特别的困难
标签:
原文地址:http://www.cnblogs.com/sisi-job/p/5563066.html