Sample Donating Funds Statically:
In this tutorial we are developing a sample like how Donating can be done, ex: by pressing the add button or sub button, Let Go....
OUT PUT Of The Tutorial:
Create Android Application:
In this tutorial we are developing a sample like how Donating can be done, ex: by pressing the add button or sub button, Let Go....
OUT PUT Of The Tutorial:
Create Android Application:
- File >> New >> Android
Application
- Enter Project
name: SampleDenotingFundsApp
- Package: com.ambilpursunil.newapp
- Keep other default selections,
click Next until you reach Finish
2.Copy
and past the following code in the MainActivity.java
package com.ambilpursunil.newapp;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
int count;
Button add,sub;
TextView dis;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
count=0;
add = (Button) findViewById(R.id.bAdd);
sub = (Button) findViewById(R.id.bSub);
dis = (TextView) findViewById(R.id.tvDisplay);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
count ++;
dis.setText("Your
Doller Total is:" +count);
}
});
sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
count --;
dis.setText("Your
Doller Totla is:" +count);
}
});
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action
bar if it is present.
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
}
2.Make the change the of activity_mani.xml file
as the below
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tvDisplay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Add Doller is 0"
android:textSize="45dp" />
<Button
android:id="@+id/bAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Add One"
android:textSize="20dp" />
<Button
android:id="@+id/bSub"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Sub one"
android:textSize="20dp" />
</LinearLayout>
3.Copy and past the code for Manifest.xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ambilpursunil.newapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.ambilpursunil.newapp.MainActivity"
android:configChanges="keyboard|keyboardHidden|orientation" >
</activity>
android:name="com.ambilpursunil.newapp.MainActivity"
android:configChanges="keyboard|keyboardHidden|orientation" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter</activity>
</application>
</manifest>
</manifest>
4.Right click on the project and Run As-->Android Application
OutPut:
When Application Launch the it will display 2 button as shown below just click on the add button to donate Or Like the post and click on the Sub to UnLike.
Stay Tune For Next Tutorial... SQlite Database in Android:
No comments:
Post a Comment