總網頁瀏覽量

關於我自己

我的相片
人生的必修課是接受無常,人生的選修課是放下執著。

2012年1月28日 星期六

SQLiteOpenHelper ~ EditText.setOnKeyListener ~ 範例: 財產分配(2)










Fund_SQLiteActivity.java


/*
     * 負責將"fund_money1"欄位的資料紀錄到SQLite中
     */
    public void SQLite_record1(String str_money1)
    {
		String[] updateFields = 
		{
				"fund_money1"
		};
		String[] updateValues = 
		{
				str_money1
		};
		Cursor c = dbHelper.select(tables[0], null, null, null, null, null, null);
		c.moveToFirst();
    	dbHelper.update(tables[0], updateFields, updateValues, null, null);
    	c.close();
    }
    /*
     * 負責將"fund_money2"欄位的資料紀錄到SQLite中
     */
    public void SQLite_record2(String str_money2)
    {
		String[] updateFields = 
		{
				"fund_money2"
		};
		String[] updateValues = 
		{
				str_money2
		};
		Cursor c = dbHelper.select(tables[0], null, null, null, null, null, null);
		c.moveToFirst();
    	dbHelper.update(tables[0], updateFields, updateValues, null, null);
    	c.close();
    }
    /*
     * 負責將"fund_money3"欄位的資料紀錄到SQLite中
     */
    public void SQLite_record3(String str_money3)
    {
		String[] updateFields = 
		{
				"fund_money3"
		};
		String[] updateValues = 
		{
				str_money3
		};
		Cursor c = dbHelper.select(tables[0], null, null, null, null, null, null);
		c.moveToFirst();
    	dbHelper.update(tables[0], updateFields, updateValues, null, null);
    	c.close();
    }
    /*
     * 負責將"fund_money4"欄位的資料紀錄到SQLite中
     */
    public void SQLite_record4(String str_money4)
    {
		String[] updateFields = 
		{
				"fund_money4"
		};
		String[] updateValues = 
		{
				str_money4
		};
		Cursor c = dbHelper.select(tables[0], null, null, null, null, null, null);
		c.moveToFirst();
    	dbHelper.update(tables[0], updateFields, updateValues, null, null);
    	c.close();
    }
    
    public void SQLite_record_item1()
    {
		String[] updateFields = 
		{
				"fund_item1"
		};
		String[] updateValues = 
		{
				et_item1.getText().toString()
		};
		Cursor c = dbHelper.select(tables[1], null, null, null, null, null, null);
		c.moveToFirst();
    	dbHelper.update(tables[1], updateFields, updateValues, null, null);
    	c.close();
		System.out.println(et_item1.getText());
    }
    public void SQLite_record_item2()
    {
		String[] updateFields = 
		{
				"fund_item2"
		};
		String[] updateValues = 
		{
				et_item2.getText().toString()
		};
		Cursor c = dbHelper.select(tables[1], null, null, null, null, null, null);
		c.moveToFirst();
    	dbHelper.update(tables[1], updateFields, updateValues, null, null);
    	c.close();
		System.out.println(et_item2.getText());
    }
    public void SQLite_record_item3()
    {
		String[] updateFields = 
		{
				"fund_item3"
		};
		String[] updateValues = 
		{
				et_item3.getText().toString()
		};
		Cursor c = dbHelper.select(tables[1], null, null, null, null, null, null);
		c.moveToFirst();
    	dbHelper.update(tables[1], updateFields, updateValues, null, null);
    	c.close();
		System.out.println(et_item3.getText());
    }
    public void SQLite_record_item4()
    {
		String[] updateFields = 
		{
				"fund_item4"
		};
		String[] updateValues = 
		{
				et_item4.getText().toString()
		};
		Cursor c = dbHelper.select(tables[1], null, null, null, null, null, null);
		c.moveToFirst();
    	dbHelper.update(tables[1], updateFields, updateValues, null, null);
    	c.close();
		System.out.println(et_item4.getText());
    }
    
    /*
     * 每一種基金有10個ImageView顯示錢幣, function意圖呈現存款多寡, 不過目前最多只有10個金幣
     */
    public void show_coin1(int money1)
    {
    	ImageView[] imageview1 = {iv1_1, iv1_2, iv1_3, iv1_4, iv1_5, iv1_6, iv1_7, iv1_8, iv1_9, iv1_10};
    	if(money1 <= 10)
    	{
    		for (int i=0; i<10; i++)
	    	{
	    		imageview1[i].setVisibility(View.INVISIBLE);
	    	}
	    	for (int i=0; i