Showing posts with label Code. Show all posts
Showing posts with label Code. Show all posts

Friday, September 28, 2018

Sqlite Database insert

package net.samaysoftware.listviewdemo;

import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.io.FileReader;
import java.io.Reader;

public class NewExpenseActivity extends AppCompatActivity implements View.OnClickListener {

    EditText etReason, etAmount;
    Button btnAddExpense;

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

        setTitle("Add expense");
        createTable();

        etReason = (EditText) findViewById(R.id.etReason);
        etAmount = (EditText) findViewById(R.id.etAmount);
        btnAddExpense = (Button) findViewById(R.id.btnAddExpense);
        btnAddExpense.setOnClickListener(this);
    }

    private void createTable() {
        SQLiteDatabase db = null;
        try {
            db = openOrCreateDatabase("SampleDB", MODE_PRIVATE,null);
            String q = "create table if not exists Expense(expenseid integer primary key autoincrement,reason varchar(100), amount integer)";
            db.execSQL(q);
        }catch (Exception ee){
            Toast.makeText(this, "Some error while creating expense table", Toast.LENGTH_LONG).show();
        }
        finally {
            if(db!=null && db.isOpen()) {
                db.close();
            }
        }

    }

    @Override    public void onClick(View view) {

        String stramount = etAmount.getText().toString();
        String strreason = etReason.getText().toString();

        SQLiteDatabase db = null;
        try {
            db = openOrCreateDatabase("SampleDB", MODE_PRIVATE,null);
            String q = "insert into Expense(amount, reason) values("+stramount+",'"+strreason+"')";
            db.execSQL(q);
            Toast.makeText(this, "Expense added successfully !!", Toast.LENGTH_LONG).show();
            Intent i = new Intent(this, ExpenseListActivity.class);
            startActivity(i);
        }catch (Exception ee){
            Toast.makeText(this, "Some error while inserting in Expense table", Toast.LENGTH_LONG).show();
        }
        finally {
            if(db!=null && db.isOpen()) {
                db.close();
            }
        }



    }
}

Thursday, September 27, 2018

Android Code with below PHP Code for Login, CategoryList, and ProductList Display with Alert Dialog code

LOGIN


package net.samaysoftware.listviewdemo;

import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import utility.HttpManager;
import utility.RequestPackage;

public class LoginActivityDemo extends AppCompatActivity implements View.OnClickListener {
    String un, pw;
    EditText etUser, etPass;
    Button btnLogin;
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login_demo);
        etUser = (EditText) findViewById(R.id.etUser);
        etPass = (EditText) findViewById(R.id.etPass);
        btnLogin = (Button) findViewById(R.id.btnMyLogin);
        btnLogin.setOnClickListener(this);


        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(LoginActivityDemo.this);
        int oldid = sp.getInt("id", -1000);
        if(oldid!=-1000){
            Intent i = new Intent(LoginActivityDemo.this, CategoryListActivity.class);
            startActivity(i);
            finish();
        }

    }

    @Override    public void onClick(View view) {
        new LoginTask().execute();
    }

    class LoginTask extends AsyncTask<String, String, String>{
        ProgressDialog pd;
        String un, pw;

        @Override        protected void onPreExecute() {
            super.onPreExecute();
            un = etUser.getText().toString();
            pw = etPass.getText().toString();
            pd = new ProgressDialog(LoginActivityDemo.this);
            pd.setTitle("Please Wait");
            pd.setMessage("Loading");
            pd.setIndeterminate(true);
            pd.setCancelable(false);
            pd.show();
        }

        @Override        protected String doInBackground(String... arr) {
            RequestPackage rp = new RequestPackage();
            rp.setMethod("GET");
            rp.setUri("http://192.168.31.10:81/2018testing/mobilesupport.php");
            rp.setParam("type","login");
            rp.setParam("un", un);
            rp.setParam("pw", pw);

            String ans = HttpManager.getData(rp);
            return ans.trim();
        }

        @Override        protected void onPostExecute(String ans) {
            super.onPostExecute(ans);

            if(pd!=null){
                pd.dismiss();
            }
            int id;
            try {
                id = Integer.parseInt(ans);
            }catch (Exception ee){
                Toast.makeText(LoginActivityDemo.this, "Cannot connect to server", Toast.LENGTH_LONG).show();
                return;
            }

            if(id==0){
                Toast.makeText(LoginActivityDemo.this, "Invalid username or password !!", Toast.LENGTH_LONG).show();
                return;
            }

            SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(LoginActivityDemo.this);
            sp.edit().putInt("id", id).apply();


            Intent i = new Intent(LoginActivityDemo.this, CategoryListActivity.class);
            startActivity(i);
            finish();

        }


    }
}


CATEGORY LIST


package net.samaysoftware.listviewdemo;

import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

import utility.HttpManager;
import utility.RequestPackage;

public class CategoryListActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
    ListView listView;
    String[] arr;
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_country_list);
        listView = (ListView) findViewById(R.id.lvDynamicCountries);

        new MyTask().execute();


    }

    @Override    public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
        String catname = arr[pos];
        Intent i = new Intent(this, ProductListActivity.class);
        i.putExtra("catname", catname);
        startActivity(i);

/*        AlertDialog.Builder builder1 = new AlertDialog.Builder(this);        builder1.setMessage("Are you sure you want to delete");        builder1.setCancelable(true);
        builder1.setPositiveButton(                "Yes",                new DialogInterface.OnClickListener() {                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();                    }                });
        builder1.setNegativeButton(                "No",                new DialogInterface.OnClickListener() {                    public void onClick(DialogInterface dialog, int id) {                        dialog.cancel();                    }                });
        AlertDialog alert11 = builder1.create();        alert11.show();*/
/*        AlertDialog.Builder builderSingle = new AlertDialog.Builder(this);        builderSingle.setIcon(R.drawable.flagindia);        builderSingle.setTitle("Select One Name:");
        final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.select_dialog_singlechoice);        arrayAdapter.add("Hardik");        arrayAdapter.add("Archit");        arrayAdapter.add("Jignesh");        arrayAdapter.add("Umang");        arrayAdapter.add("Gatti");
        builderSingle.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {            @Override            public void onClick(DialogInterface dialog, int which) {                dialog.dismiss();            }        });
        builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {            @Override            public void onClick(DialogInterface dialog, int which) {                String strName = arrayAdapter.getItem(which);                AlertDialog.Builder builderInner = new AlertDialog.Builder(CategoryListActivity.this);                builderInner.setMessage(strName);                builderInner.setTitle("Your Selected Item is");                builderInner.setPositiveButton("Ok", new DialogInterface.OnClickListener() {                    @Override                    public void onClick(DialogInterface dialog,int which) {                        dialog.dismiss();                    }                });                builderInner.show();            }        });        builderSingle.show();
*/
    }

    class MyTask extends AsyncTask<String, String, String>{

        ProgressDialog pd = null;
        @Override        protected String doInBackground(String... strings) {
            RequestPackage rp = new RequestPackage();
            rp.setMethod("GET");
            rp.setUri("http://192.168.31.10:81/2018testing/mobilesupport.php");
            rp.setParam("type","getcategorylist");
            String ans = HttpManager.getData(rp);
            return ans.trim();
        }

        @Override        protected void onPreExecute() {
            super.onPreExecute();
            pd = new ProgressDialog(CategoryListActivity.this);
            pd.setIndeterminate(true);
            pd.setMessage("Loading....");
            pd.setCancelable(false);
            pd.setTitle("Please Wait");
            pd.show();
        }

        @Override        protected void onPostExecute(String ans) {
            super.onPostExecute(ans);

            arr = ans.split(",");



            ArrayAdapter<String> aa = new ArrayAdapter<>(CategoryListActivity.this, android.R.layout.simple_list_item_1, android.R.id.text1, arr);
            listView.setAdapter(aa);
            listView.setOnItemClickListener(CategoryListActivity.this);
            pd.dismiss();
        }
    }
}


PRODUCT LIST


package net.samaysoftware.listviewdemo;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import utility.HttpManager;
import utility.RequestPackage;

public class ProductListActivity extends AppCompatActivity{
    ListView listView;
    String[] arr;
    String catname;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        catname = getIntent().getStringExtra("catname");

        setContentView(R.layout.activity_country_list);
        listView = (ListView) findViewById(R.id.lvDynamicCountries);

        new MyTask().execute();


    }


    class MyTask extends AsyncTask<String, String, String>{

        ProgressDialog pd = null;
        @Override
        protected String doInBackground(String... strings) {
            RequestPackage rp = new RequestPackage();
            rp.setMethod("GET");
            rp.setUri("http://192.168.31.10:81/2018testing/mobilesupport.php");
            rp.setParam("type","getproductlist");
            rp.setParam("catname",catname);

            String ans = HttpManager.getData(rp);
            return ans.trim();
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pd = new ProgressDialog(ProductListActivity.this);
            pd.setIndeterminate(true);
            pd.setMessage("Loading....");
            pd.setCancelable(false);
            pd.setTitle("Please Wait");
            pd.show();
        }

        @Override
        protected void onPostExecute(String ans) {
            super.onPostExecute(ans);

            arr = ans.split(",");



            ArrayAdapter<String> aa = new ArrayAdapter<String>(ProductListActivity.this, android.R.layout.simple_list_item_1, android.R.id.text1, arr);
            listView.setAdapter(aa);



            pd.dismiss();
        }
    }
}


Thursday, September 20, 2018

PHP Code for MobileSupport.php

<?php
$type = $_REQUEST["type"];
if($type=="login"){
$username= $_REQUEST["un"];
$pw= $_REQUEST["pw"];

if($username=="v" && $pw=="v"){
echo "4";
}
else{
echo "0";
}
}
else if($type=="getcategorylist"){
echo "Clothes,Electronics,Food";
}
else if($type=="getproductlist"){
$catname = $_REQUEST["catname"];
if($catname == "Clothes"){
echo "Tshirt,Jeans,Shirt";
}
if($catname == "Electronics"){
echo "TV,Mobile,Laptop";
}
if($catname == "Food"){
echo "Burger,Pizza,Noodles";
}

}
else if($type=="getmyprofile"){

}
else if($type=="getproductdetails"){

}
?>

Monday, September 17, 2018

Show List of Countries using API

package net.samaysoftware.listviewdemo;

import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.*;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

import utility.HttpManager;
import utility.RequestPackage;

public class CountryList extends AppCompatActivity {
    ListView listView;
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_country_list);
        listView = (ListView) findViewById(R.id.lvDynamicCountries);

        new MyTask().execute();

    }
    class MyTask extends AsyncTask<String, String, String>{

        ProgressDialog pd = null;
        @Override        protected String doInBackground(String... strings) {
            RequestPackage rp = new RequestPackage();
            rp.setMethod("GET");
            rp.setUri("https://restcountries.eu/rest/v2/all");
            String ans = HttpManager.getData(rp);
            return ans;
        }

        @Override        protected void onPreExecute() {
            super.onPreExecute();
            pd = new ProgressDialog(CountryList.this);
            pd.setIndeterminate(true);
            pd.setMessage("Loading....");
            pd.setCancelable(false);
            pd.setTitle("Please Wait");
            pd.show();
        }

        @Override        protected void onPostExecute(String ans) {
            super.onPostExecute(ans);

            ArrayList<String> arrlist = new ArrayList<>();

            try {
                JSONArray rootarr = new JSONArray(ans);

                for(int i = 0; i <rootarr.length(); i++){
                    JSONObject obj = rootarr.getJSONObject(i);
                    String countryname = obj.getString("name");
                    arrlist.add(countryname);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }


            ArrayAdapter<String> aa = new ArrayAdapter<String>(CountryList.this, android.R.layout.simple_list_item_1, android.R.id.text1, arrlist);
            listView.setAdapter(aa);



            pd.dismiss();
        }
    }
}

Friday, August 31, 2018

Web Connectivity from Android

You need 2 reference files for connecting to any webserver

HttpManager.java

RequestPackage.java

Download the above mentioned files and paste them in Android Studio

Tuesday, August 28, 2018

File Manager Code

package net.samaysoftware.sampleapplication12345;

import android.content.Intent;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
public class FMMainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
    ListView lv;
    String[] from = {"fname","ftype"};
    int[] to = {android.R.id.text1, android.R.id.text2};
    ArrayList<HashMap<String, String>> data = new ArrayList<>();
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fmmain);
        lv = (ListView) findViewById(R.id.fmlv);
        generateData();
        SimpleAdapter sa = new SimpleAdapter(this, data, android.R.layout.simple_list_item_2,from, to);
        lv.setAdapter(sa);
        lv.setOnItemClickListener(this);
    }
    private void generateData() {
        File froot = null;
        if(getIntent().getStringExtra("abcd")==null) {
            froot = Environment.getExternalStorageDirectory();
        }
        else{
            String fpath = getIntent().getStringExtra("abcd");
            froot = new File(fpath);
            setTitle(froot.getName());
        }
        File[] arr = froot.listFiles();
        for(File f: arr){
            String name = f.getName();
            String type = f.isFile()?"File":"Folder";
            HashMap<String, String> map = new HashMap<>();
            map.put("fname", name);
            map.put("ftype", type);
            map.put("fpath", f.getAbsolutePath());
            data.add(map);
        }
    }

    @Override    public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
        String fpath = data.get(pos).get("fpath");
        File cf = new File(fpath);
        if(cf.isDirectory()){
            Intent i = new Intent(this, FMMainActivity.class);
            i.putExtra("abcd", fpath);
            startActivity(i);
        }else{

        }

    }
}


Note: Add permission in Manifest file as below:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
just before the <application> tag and inside the <manifest> tag.





Saturday, August 11, 2018

Static ListView with SimpleAdapter

package net.samaysoftware.listviewdemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.*;

import java.util.ArrayList;
import java.util.HashMap;

public class AnotherListViewActivity extends AppCompatActivity {

    ListView lvAnother;
    String[] from = {"a","b"};
    int[] to = {R.id.tvState, R.id.tvCapital};
    ArrayList<HashMap<String, String>> data = new ArrayList<>();

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_another_list_view);
        lvAnother = (ListView) findViewById(R.id.lvanother);

        prepareData();
        SimpleAdapter sa = new SimpleAdapter(this, data, R.layout.repeating_unit_2_items,from, to);
        lvAnother.setAdapter(sa);


    }

    private void prepareData() {
        HashMap<String, String> map1 = new HashMap<>();
        map1.put("a", "Gujarat");
        map1.put("b", "Gandhinagar");

        HashMap<String, String> map2 = new HashMap<>();
        map2.put("a", "Rajasthan");
        map2.put("b", "Jaipur");

        HashMap<String, String> map3 = new HashMap<>();
        map3.put("a", "Maharasthra");
        map3.put("b", "Mumbai");

        HashMap<String, String> map4 = new HashMap<>();
        map4.put("a", "Madhyapradesh");
        map4.put("b", "Bhopal");

        data.add(map1);
        data.add(map2);
        data.add(map3);
        data.add(map4);


    }
}

ListView with ArrayAdapter (Dynamic)

package net.samaysoftware.listviewdemo;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;

import java.util.ArrayList;

public class CityListActivity extends AppCompatActivity implements AdapterView.OnItemClickListener, View.OnClickListener {

    ListView lvCities;
    ArrayList<String> arr = new ArrayList<>();
    EditText etCityName;
    Button btnSave;
    ArrayAdapter<String> aa;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findAllViews();
        aa = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,android.R.id.text1,arr);
        lvCities.setAdapter(aa);
        lvCities.setOnItemClickListener(this);
        btnSave.setOnClickListener(this);
    }

    private void findAllViews() {
        lvCities = (ListView) findViewById(R.id.lvCities);
        etCityName = (EditText) findViewById(R.id.etCityName);
        btnSave = (Button)findViewById(R.id.btnSave);
    }

    @Override    public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
        String selectedcity = arr.get(pos);
        Toast.makeText(this, "You clicked on position: "+selectedcity, Toast.LENGTH_SHORT).show();

        Intent i = new Intent(this, CityDetailActivity.class);
        i.putExtra("abcd",selectedcity);
        startActivity(i);
    }

    @Override    public void onClick(View view) {
        String name = etCityName.getText().toString();
        arr.add(name);
        aa.notifyDataSetChanged();
    }
}

Wednesday, August 1, 2018

Calculator

package net.samaysoftware.sampleproject12345;

import android.renderscript.Double2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import org.w3c.dom.Text;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    Button btn0, btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btnplus, btnminus, btnmult, btndiv, btneq, btndot;
    TextView tvScreen;
    Button[] arr= null;


    double num1;
    int op;

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

        findAllViews();
        arr = new Button[]{btn0, btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btnplus, btnminus, btnmult, btndiv, btneq, btndot};
        for(int i = 0; i<arr.length;i++){
            arr[i].setOnClickListener(this);
        }

    }

    private void findAllViews() {
        btn0 = (Button) findViewById(R.id.btn0);
        btn1 = (Button) findViewById(R.id.btn1);
        btn2 = (Button) findViewById(R.id.btn2);
        btn3 = (Button) findViewById(R.id.btn3);
        btn4 = (Button) findViewById(R.id.btn4);
        btn5 = (Button) findViewById(R.id.btn5);
        btn6 = (Button) findViewById(R.id.btn6);
        btn7 = (Button) findViewById(R.id.btn7);
        btn8 = (Button) findViewById(R.id.btn8);
        btn9 = (Button) findViewById(R.id.btn9);
        btndot = (Button) findViewById(R.id.btndot);
        btnplus = (Button) findViewById(R.id.btnplus);
        btnminus = (Button) findViewById(R.id.btnminus);
        btnmult = (Button) findViewById(R.id.btnmult);
        btndiv = (Button) findViewById(R.id.btndiv);
        btneq = (Button) findViewById(R.id.btneq);
        tvScreen = (TextView) findViewById(R.id.tvScreen);
    }

    @Override    public void onClick(View view) {
        Button clickedbutton = (Button) view;

        if(view== btn0 || view== btn1 || view== btn2 || view== btn3 || view== btn4 || view== btn5 || view== btn7 || view== btn6 || view== btn8 || view== btn9 || view== btndot ){
            String oldvalue = tvScreen.getText().toString();

            if(view==btndot && oldvalue.contains(".")){
                return;
            }
            String newvalue = oldvalue + clickedbutton.getText();
            tvScreen.setText(newvalue);

        }
        else if(view== btnplus || view== btnminus || view== btnmult || view== btndiv ){
            String oldvalue = tvScreen.getText().toString();
            num1 = Double.parseDouble(oldvalue);
            if(view==btnplus){
                op=1;
            }

            if(view==btnminus){
                op=2;
            }
            if(view==btnmult){
                op=3;
            }
            if(view==btndiv){
                op=4;
            }
            tvScreen.setText("");

        }
        else if(view == btneq){
            double num2 = Double.parseDouble(tvScreen.getText().toString());
            double ans = 0;
            switch (op){
                case 1:
                    ans = num1 + num2;
                    break;
                case 2:
                    ans = num1-num2;
                    break;
                case 3:
                    ans = num1 * num2;
                    break;
                case 4:
                    ans = num1 / num2;
                    break;
            }
            tvScreen.setText(ans+"");



        }
    }
}

Monday, July 23, 2018

Counter App

Design for Counter App (Layout File)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"    
xmlns:app="http://schemas.android.com/apk/res-auto"    
xmlns:tools="http://schemas.android.com/tools"    
android:layout_width="match_parent"    
android:orientation="vertical"    
android:padding="16dp"
android:layout_height="match_parent"    
tools:context="net.samaysoftware.sampleapplication12345.MainActivity">
    <TextView
        android:id="@+id/tvNumber"        
        android:layout_width="match_parent"        
        android:layout_height="wrap_content"
        android:textSize="80sp"        
        android:gravity="center"        
        android:text="1" />


    <Button        
        android:id="@+id/btnIncrement"        
        android:layout_width="match_parent"        
        android:layout_height="wrap_content"        
        android:text="Increment" />


    <Button        
        android:id="@+id/btnDecrement"        
        android:layout_width="match_parent"        
        android:layout_height="wrap_content"        
        android:text="Decrement" />


</LinearLayout>


Code for Counter App (Java File)

package net.samaysoftware.sampleapplication12345;

import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    TextView tvNumber;
    Button btnIncrement, btnDecrement;
    @Override    
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tvNumber = (TextView)findViewById(R.id.tvNumber);
        btnIncrement = (Button) findViewById(R.id.btnIncrement);
        btnDecrement = (Button) findViewById(R.id.btnDecrement);
        tvNumber.setText("0");
        btnIncrement.setOnClickListener(this);
        btnDecrement.setOnClickListener(this);
        tvNumber.setOnClickListener(this);
    }
    @Override    
    public void onClick(View view) {
        if(view==btnIncrement) {
            String number = tvNumber.getText().toString();
            int no = Integer.parseInt(number);
            no++;
            String newnumber = String.valueOf(no);
            tvNumber.setText(newnumber);
        }else if(view== btnDecrement){
            String number = tvNumber.getText().toString();
            int no = Integer.parseInt(number);
            no--;
            String newnumber = String.valueOf(no);
            tvNumber.setText(newnumber);
        }
        else if(view==tvNumber){
            tvNumber.setText("100");

        }
    }
}

Near by App

https://drive.google.com/file/d/0B2ag35s4X53Eb2pSQVI1SzNudE0/view