Make a Daily Money Count Android Application
activity_money.xml
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#111111"
tools:context="com.example.dailymoneycount.Money" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="96dp"
android:layout_y="6dp"
android:text="Money Count"
android:textColor="#FFFFFF"
android:textSize="20dip" />
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="4dp"
android:layout_y="62dp"
android:text="@string/Date"
android:textColor="#FFFFFF"
android:textSize="20dp" />
<TextView
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="4dp"
android:layout_y="128dp"
android:text="@string/Expense"
android:textColor="#FFFFFF"
android:textSize="20dp" />
<EditText
android:id="@+id/txtdate"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_x="133dp"
android:layout_y="57dp"
android:background="#FFFFFF"
android:ems="10"
android:hint="01/01/2000"
android:inputType="text" />
<EditText
android:id="@+id/txtexpense"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_x="135dp"
android:layout_y="120dp"
android:background="#FFFFFF"
android:ems="10"
android:hint="Total Expense"
android:inputType="number" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/txtdes"
android:layout_width="162dp"
android:layout_height="71dp"
android:layout_x="135dp"
android:layout_y="178dp"
android:background="#FFFFFF"
android:ems="10"
android:hint="Your Expense Description" />
<TextView
android:id="@+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="4dp"
android:layout_y="208dp"
android:text="@string/Description"
android:textColor="#FFFFFF"
android:textSize="20dp" />
<Button
android:id="@+id/btninsert"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_x="42dp"
android:layout_y="282dp"
android:text="Insert" />
<Button
android:id="@+id/btnupdate"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_x="152dp"
android:layout_y="282dp"
android:text="Update" />
<Button
android:id="@+id/btndelete"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_x="44dp"
android:layout_y="340dp"
android:text="Delete" />
<Button
android:id="@+id/btnsearch"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_x="154dp"
android:layout_y="338dp"
android:text="Search" />
<Button
android:id="@+id/btnall"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_x="46dp"
android:layout_y="394dp"
android:text="View All" />
<Button
android:id="@+id/btndevelop"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_x="158dp"
android:layout_y="390dp"
android:text="Develop" />
</AbsoluteLayout>
Money.java
package com.example.dailymoneycount;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Money extends ActionBarActivity
{
Button btndevelop,btninsert,btnall,btnsearch,btndelete,btnupdate;
EditText txtdate,txtexpense,txtdes;
SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_money);
btndevelop=(Button)findViewById(R.id.btndevelop);
btndelete=(Button)findViewById(R.id.btndelete);
btninsert=(Button)findViewById(R.id.btninsert);
btnupdate=(Button)findViewById(R.id.btnupdate);
btnall=(Button)findViewById(R.id.btnall);
btnsearch=(Button)findViewById(R.id.btnsearch);
txtdate=(EditText)findViewById(R.id.txtdate);
txtexpense=(EditText)findViewById(R.id.txtexpense);
txtdes=(EditText)findViewById(R.id.txtdes);
db=openOrCreateDatabase("Money", Context.MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS Money_count(dt VARCHAR,total VARCHAR,description VARCHAR);");
btndevelop.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0)
{
Toast.makeText(getApplicationContext(), "Vishal And Vivek", Toast.LENGTH_LONG).show();
}
});
btninsert.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0)
{
if(txtdate.getText().toString().trim().length()==0 || txtexpense.getText().toString().trim().length()==0 || txtdes.getText().toString().trim().length()==0)
{
Toast.makeText(getApplicationContext(), "Enter All Data", Toast.LENGTH_LONG).show();
}
else
{
db.execSQL("INSERT INTO Money_count VALUES('"+txtdate.getText()+"','"+txtexpense.getText()+
"','"+txtdes.getText()+"');");
Toast.makeText(getApplicationContext(), "Data Save Successfull", Toast.LENGTH_LONG).show();
txtdate.setText("");
txtexpense.setText("");
txtdes.setText("");
}
}
});
btnupdate.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0)
{
if(txtdate.getText().toString().trim().length()==0)
{
showMessage("Error", "Please Enter Date For Record Update");
return;
}
Cursor c=db.rawQuery("SELECT * FROM Money_count WHERE dt='"+txtdate.getText()+"'", null);
if(c.moveToFirst())
{
db.execSQL("UPDATE Money_count SET total='"+txtexpense.getText()+"',description='"+txtdes.getText()+
"' WHERE dt='"+txtdate.getText()+"'");
showMessage("Successfull", "Record Update Successfull");
txtdate.setText("");
txtexpense.setText("");
txtdes.setText("");
}
else
{
showMessage("Error", "You Enter Invalid Date");
}
}
});
btndelete.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0)
{
if(txtdate.getText().toString().trim().length()==0)
{
showMessage("Error", "Please Enter Date");
return;
}
Cursor c=db.rawQuery("SELECT * FROM Money_count WHERE dt='"+txtdate.getText()+"'", null);
if(c.moveToFirst())
{
db.execSQL("DELETE FROM Money_count WHERE dt='"+txtdate.getText()+"'");
showMessage("Successfull", "Record Delete Successfull");
txtdate.setText("");
}
else
{
showMessage("Error", "You Entered Invalid Date");
}
}
});
btnsearch.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0)
{
if(txtdate.getText().toString().trim().length()==0)
{
showMessage("Error", "Please Enter The Date");
return;
}
Cursor c=db.rawQuery("SELECT * FROM Money_count WHERE dt='"+txtdate.getText()+"'", null);
if(c.moveToFirst())
{
txtexpense.setText(c.getString(1));
txtdes.setText(c.getString(2));
// editCollege.setText(c.getString(3));
}
else
{
showMessage("Error", "Entered date Is Incorrect");
txtdate.setText("");
txtexpense.setText("");
txtdes.setText("");
}
}
});
btnall.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0)
{
Cursor c=db.rawQuery("SELECT * FROM Money_count", null);
if(c.getCount()==0)
{
showMessage("Error", "Sorry This Date Record NotFound");
return;
}
StringBuffer buffer=new StringBuffer();
while(c.moveToNext())
{
buffer.append("Date: "+c.getString(0)+"\n");
buffer.append("Expense: "+c.getString(1)+"\n");
buffer.append("Desc: "+c.getString(2)+"\n\n");
}
showMessage("Money Details", buffer.toString());
}
});
}
public void showMessage(String title,String message)
{
Builder builder=new Builder(this);
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(message);
builder.show();
}
}
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#111111"
tools:context="com.example.dailymoneycount.Money" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="96dp"
android:layout_y="6dp"
android:text="Money Count"
android:textColor="#FFFFFF"
android:textSize="20dip" />
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="4dp"
android:layout_y="62dp"
android:text="@string/Date"
android:textColor="#FFFFFF"
android:textSize="20dp" />
<TextView
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="4dp"
android:layout_y="128dp"
android:text="@string/Expense"
android:textColor="#FFFFFF"
android:textSize="20dp" />
<EditText
android:id="@+id/txtdate"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_x="133dp"
android:layout_y="57dp"
android:background="#FFFFFF"
android:ems="10"
android:hint="01/01/2000"
android:inputType="text" />
<EditText
android:id="@+id/txtexpense"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_x="135dp"
android:layout_y="120dp"
android:background="#FFFFFF"
android:ems="10"
android:hint="Total Expense"
android:inputType="number" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/txtdes"
android:layout_width="162dp"
android:layout_height="71dp"
android:layout_x="135dp"
android:layout_y="178dp"
android:background="#FFFFFF"
android:ems="10"
android:hint="Your Expense Description" />
<TextView
android:id="@+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="4dp"
android:layout_y="208dp"
android:text="@string/Description"
android:textColor="#FFFFFF"
android:textSize="20dp" />
<Button
android:id="@+id/btninsert"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_x="42dp"
android:layout_y="282dp"
android:text="Insert" />
<Button
android:id="@+id/btnupdate"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_x="152dp"
android:layout_y="282dp"
android:text="Update" />
<Button
android:id="@+id/btndelete"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_x="44dp"
android:layout_y="340dp"
android:text="Delete" />
<Button
android:id="@+id/btnsearch"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_x="154dp"
android:layout_y="338dp"
android:text="Search" />
<Button
android:id="@+id/btnall"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_x="46dp"
android:layout_y="394dp"
android:text="View All" />
<Button
android:id="@+id/btndevelop"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_x="158dp"
android:layout_y="390dp"
android:text="Develop" />
</AbsoluteLayout>
Money.java
package com.example.dailymoneycount;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Money extends ActionBarActivity
{
Button btndevelop,btninsert,btnall,btnsearch,btndelete,btnupdate;
EditText txtdate,txtexpense,txtdes;
SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_money);
btndevelop=(Button)findViewById(R.id.btndevelop);
btndelete=(Button)findViewById(R.id.btndelete);
btninsert=(Button)findViewById(R.id.btninsert);
btnupdate=(Button)findViewById(R.id.btnupdate);
btnall=(Button)findViewById(R.id.btnall);
btnsearch=(Button)findViewById(R.id.btnsearch);
txtdate=(EditText)findViewById(R.id.txtdate);
txtexpense=(EditText)findViewById(R.id.txtexpense);
txtdes=(EditText)findViewById(R.id.txtdes);
db=openOrCreateDatabase("Money", Context.MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS Money_count(dt VARCHAR,total VARCHAR,description VARCHAR);");
btndevelop.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0)
{
Toast.makeText(getApplicationContext(), "Vishal And Vivek", Toast.LENGTH_LONG).show();
}
});
btninsert.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0)
{
if(txtdate.getText().toString().trim().length()==0 || txtexpense.getText().toString().trim().length()==0 || txtdes.getText().toString().trim().length()==0)
{
Toast.makeText(getApplicationContext(), "Enter All Data", Toast.LENGTH_LONG).show();
}
else
{
db.execSQL("INSERT INTO Money_count VALUES('"+txtdate.getText()+"','"+txtexpense.getText()+
"','"+txtdes.getText()+"');");
Toast.makeText(getApplicationContext(), "Data Save Successfull", Toast.LENGTH_LONG).show();
txtdate.setText("");
txtexpense.setText("");
txtdes.setText("");
}
}
});
btnupdate.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0)
{
if(txtdate.getText().toString().trim().length()==0)
{
showMessage("Error", "Please Enter Date For Record Update");
return;
}
Cursor c=db.rawQuery("SELECT * FROM Money_count WHERE dt='"+txtdate.getText()+"'", null);
if(c.moveToFirst())
{
db.execSQL("UPDATE Money_count SET total='"+txtexpense.getText()+"',description='"+txtdes.getText()+
"' WHERE dt='"+txtdate.getText()+"'");
showMessage("Successfull", "Record Update Successfull");
txtdate.setText("");
txtexpense.setText("");
txtdes.setText("");
}
else
{
showMessage("Error", "You Enter Invalid Date");
}
}
});
btndelete.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0)
{
if(txtdate.getText().toString().trim().length()==0)
{
showMessage("Error", "Please Enter Date");
return;
}
Cursor c=db.rawQuery("SELECT * FROM Money_count WHERE dt='"+txtdate.getText()+"'", null);
if(c.moveToFirst())
{
db.execSQL("DELETE FROM Money_count WHERE dt='"+txtdate.getText()+"'");
showMessage("Successfull", "Record Delete Successfull");
txtdate.setText("");
}
else
{
showMessage("Error", "You Entered Invalid Date");
}
}
});
btnsearch.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0)
{
if(txtdate.getText().toString().trim().length()==0)
{
showMessage("Error", "Please Enter The Date");
return;
}
Cursor c=db.rawQuery("SELECT * FROM Money_count WHERE dt='"+txtdate.getText()+"'", null);
if(c.moveToFirst())
{
txtexpense.setText(c.getString(1));
txtdes.setText(c.getString(2));
// editCollege.setText(c.getString(3));
}
else
{
showMessage("Error", "Entered date Is Incorrect");
txtdate.setText("");
txtexpense.setText("");
txtdes.setText("");
}
}
});
btnall.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0)
{
Cursor c=db.rawQuery("SELECT * FROM Money_count", null);
if(c.getCount()==0)
{
showMessage("Error", "Sorry This Date Record NotFound");
return;
}
StringBuffer buffer=new StringBuffer();
while(c.moveToNext())
{
buffer.append("Date: "+c.getString(0)+"\n");
buffer.append("Expense: "+c.getString(1)+"\n");
buffer.append("Desc: "+c.getString(2)+"\n\n");
}
showMessage("Money Details", buffer.toString());
}
});
}
public void showMessage(String title,String message)
{
Builder builder=new Builder(this);
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(message);
builder.show();
}
}
Make a Daily Money Count Android Application
Reviewed by Unknown
on
6:07:00 PM
Rating:
I admire what you have done here. I like the part where you say you are doing this to give back but I would assume by all the comments that this is working for you as well. view
ReplyDelete