Tuesday, 14 February 2017

First Project about quanity changing


input

XML CODE

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:orientation="vertical"    android:id="@+id/activity_main"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context="com.example.saketh.firstprojectman.MainActivity">
    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="quantity"        android:layout_marginBottom="16dp"        android:textAllCaps="true"/>
    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="0"        android:textSize="16sp"        android:layout_marginBottom="16dp"        android:textAllCaps="true"        android:id="@+id/quantity_text_view"        android:textColor="@android:color/black"/>
    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="order"        android:onClick="submitOrder"/>

</LinearLayout>


Main Activity.java
package com.example.saketh.firstprojectman; /** * Add your package below. Package name can be found in the project's AndroidManifest.xml file. * This is the package name our example uses: * * package com.example.android.justjava; */
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import com.example.saketh.firstprojectman.R;

/** * This app displays an order form to order coffee. */public class MainActivity extends AppCompatActivity {

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    /**     * This method is called when the order button is clicked.     */    public void submitOrder(View view) {
        display(1);
    }

    /**     * This method displays the given quantity value on the screen.     */    private void display(int number) {
        TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
        quantityTextView.setText("" + number);
    }
}

if any error occurs point on that error and press ALT+ENTER A.A bulb will display which is in red color and change the package name.

output





When you will click on that button it will show 1

No comments:

Post a Comment