Create main.xml
Create Main.java
}
Android Maiifest.xml
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:textSize="30dp"
android:gravity="center"
android:layout_gravity="center"/>
<Button
android:id="@+id/Add"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="Add"
android:layout_gravity="center"/>
<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Substract"
android:layout_marginTop="50dp"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
Create Main.java
package com.example.FirstProject;
import
android.app.Activity;
import
android.os.Bundle;
import
android.view.View;
import
android.view.View.OnClickListener;
import android.widget.Button;
import
android.widget.TextView;
public class
FirstProjectActivity extends Activity {
int counter;
Button add,sub;
TextView display;
@Override
protected void
onCreate(Bundle savedInstanceState) {
// TODO
Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
counter=0;
add=(Button)findViewById(R.id.Add);
sub=(Button)findViewById(R.id.button2);
display=(TextView)findViewById(R.string.hello);
add.setOnClickListener(new
OnClickListener() {
//
TODO Auto-generated method stub
counter++;
display.setText("Total
is: " + counter);
}
});
sub.setOnClickListener(new OnClickListener() {
public
void onClick(View v) {
//
TODO Auto-generated method stub
counter--;
display.setText("Total
is: " + counter);
}
});
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.prince.FirstProject"
android:versionCode="1"
android:versionName="1.0"
>
<uses-sdk
android:minSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
>
<activity
android:label="@string/app_name"
android:name=".FirstProjectActivity"
>
<intent-filter >
<action
android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>
</manifest>
No comments:
Post a Comment