Twitter Facebook Delicious Digg Stumbleupon Favorites More

Thursday, 30 November 2017

dog cat app


PART 1 BASIC-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
package com.example.viraj.petbioapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private ImageView dog;
    private ImageView cat;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        dog = (ImageView) findViewById(R.id.id_dog);
        cat = (ImageView) findViewById(R.id.id_cat);

        dog.setOnClickListener(this);
        cat.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.id_dog:
                Toast.makeText(getApplicationContext(), "dog clicked", Toast.LENGTH_LONG).show();
                break;
            case R.id.id_cat:
                Toast.makeText(getApplicationContext(), "cat clicked", Toast.LENGTH_LONG).show();
                break;
        }
    }
}
PART 2-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
create another bio activity single page to display either dog or either cat and its name
main activity
package com.example.viraj.petbioapp;

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

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private ImageView dog;
    private ImageView cat;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        dog = (ImageView) findViewById(R.id.id_dog);
        cat = (ImageView) findViewById(R.id.id_cat);

        dog.setOnClickListener(this);
        cat.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.id_dog:
               // Toast.makeText(getApplicationContext(), "dog clicked", Toast.LENGTH_LONG).show();
                Intent dogintent=new Intent(getApplicationContext(),BioActivity.class);
               dogintent.putExtra("key_is_name","DOG");
               dogintent.putExtra("key_is_Decr","Dog is very lovely animal");
               startActivity(dogintent);
                break;
            case R.id.id_cat:
                //Toast.makeText(getApplicationContext(), "cat clicked", Toast.LENGTH_LONG).show();
               Intent catintent = new Intent(getApplicationContext(),BioActivity.class);
                catintent.putExtra("key_is_name","CAT");
                catintent.putExtra("key_is_Decr","Cat is very lovely animal");
                startActivity(catintent);
                break;
        }
    }
}

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_height="match_parent"
    tools:context="com.example.viraj.petbioapp.MainActivity">

    <ImageView
        android:id="@+id/id_dog"
        android:layout_width="172dp"
        android:layout_height="141dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="52dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/dogimage" />

    <ImageView
        android:id="@+id/id_cat"
        android:layout_width="172dp"
        android:layout_height="185dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="96dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_dog"
        app:srcCompat="@drawable/cat" />
</android.support.constraint.ConstraintLayout>



secondpage.java////////////////////////////////////////////////////////////

package com.example.viraj.petbioapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

public class BioActivity extends AppCompatActivity {
    private ImageView imageView_all;
    private TextView txt1_name, txt2_desc;
private Bundle extras;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bio);

        imageView_all = (ImageView) findViewById(R.id.id_imageall);
        txt1_name = (TextView) findViewById(R.id.id_name);
        txt2_desc = (TextView) findViewById(R.id.id_description);

        extras=getIntent().getExtras();
        if(extras!=null)
        {
            String name=extras.getString("key_is_name");
            String desc=extras.getString("key_is_Decr");
            setup(name,desc);
        }

    }
    public void setup(String name,String desc)
    {
if (name.equals("DOG"))
{
    imageView_all.setImageDrawable(getDrawable(R.drawable.dogimage));
    txt1_name.setText(name);
    txt2_desc.setText(desc);
//we show dog stuff
}
else if(name.equals("CAT"))
{
    //we show cat stuff
     imageView_all.setImageDrawable(getDrawable(R.drawable.cat));
    txt1_name.setText(name);
    txt2_desc.setText(desc);
}
    }
}

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_height="match_parent"
    tools:context="com.example.viraj.petbioapp.BioActivity">

    <ImageView
        android:id="@+id/id_imageall"
        android:layout_width="294dp"
        android:layout_height="214dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="16dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.422"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@mipmap/ic_launcher" />

    <TextView
        android:id="@+id/id_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="124dp"
        android:text="TextView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_imageall" />

    <TextView
        android:id="@+id/id_description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="84dp"
        android:text="TextView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_name" />
</android.support.constraint.ConstraintLayout>


Share:

Intent Activity For Result

Intent Activity For Result


first page

package com.gohool.showactivity.showactivity;

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

import static android.app.Activity.RESULT_OK;

public class FirstActivity extends AppCompatActivity {
    private Button goToSecondButton;
    private final int REQUEST_CODE = 2;

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

        goToSecondButton = (Button) findViewById(R.id.showButtonID);
        goToSecondButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Code goes here
                Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
                intent.putExtra("Message", "Hello From First Activity");
                intent.putExtra("SecondMessage", "Hello Again");
                intent.putExtra("Value", 123);

                //startActivity(intent);
                startActivityForResult(intent, REQUEST_CODE);
                //startActivity(new Intent(FirstActivity.this, SecondActivity.class));
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE) {
             if (resultCode == RESULT_OK) {
                  String result = data.getStringExtra("returnData");

                 Toast.makeText(FirstActivity.this, result, Toast.LENGTH_LONG).show();


             }
        }


    }
}





second activity  

package com.gohool.showactivity.showactivity;

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

public class SecondActivity extends AppCompatActivity {

    private TextView showMessage;
    private Button backButton;

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

        Bundle extras = getIntent().getExtras();

        showMessage = (TextView) findViewById(R.id.messageTextView);
        backButton = (Button) findViewById(R.id.goBackButtonID);

        //check
        if (extras != null) {
            String message = extras.getString("SecondMessage");
            int myInt = extras.getInt("Value");

            showMessage.setText("Message is" + message + " and : " + String.valueOf(myInt));
        }


        backButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //code goes here
                Intent returnIntent = getIntent();
                returnIntent.putExtra("returnData", "From SecondActivity");
                setResult(RESULT_OK, returnIntent);
                finish();

            }
        });
    }
}

Share:

Tuesday, 28 November 2017

Tip calculator

package com.example.viraj.tipcalculator;

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.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private EditText enteramount;
    private SeekBar seekbar_tip_sleekbar;
    private TextView seekbar_text_amount;
    private Button caluclate_button;
    private TextView text_your_tip_is;
    private TextView total_amount_final;

    private int seekbarpercentage;
    private float enterbillfloat;

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

        enteramount = (EditText) findViewById(R.id.id_enteramount);
        seekbar_tip_sleekbar = (SeekBar) findViewById(R.id.id_seekbar);
        seekbar_text_amount = (TextView) findViewById(R.id.id_text_seekpercentage);
        caluclate_button = (Button) findViewById(R.id.id_submitbutton);
        text_your_tip_is = (TextView) findViewById(R.id.id_text_yourtip_is);
        total_amount_final = (TextView) findViewById(R.id.id_text_totalamount);
        //----------------------------
        seekbar_text_amount.setText("YOU SELECT " + seekbar_tip_sleekbar.getProgress() + "%");
        //-----------------------------
        caluclate_button.setOnClickListener(this);
        //-----------------------------
        seekbar_tip_sleekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                seekbar_text_amount.setText("YOU SELECT " + String.valueOf(seekbar_tip_sleekbar.getProgress()) + "%");
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                Toast.makeText(getApplicationContext(), "START", Toast.LENGTH_LONG).show();
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                seekbarpercentage = seekbar_tip_sleekbar.getProgress();
                //Toast.makeText(getApplicationContext(), "STOP", Toast.LENGTH_LONG).show();
            }
        });
    }

    //-----------------------------
    @Override
    public void onClick(View view) {
        calculate();
    }

    public void calculate() {
        float result = 0.0f;
        if (!enteramount.getText().toString().equals("")) {

            enterbillfloat = Float.parseFloat(enteramount.getText().toString());
            result=(enterbillfloat*seekbarpercentage/100);
            text_your_tip_is.setText("TIP ->" + String.valueOf(result));

            total_amount_final.setText("TOTAL AMOUNT IS ->"+ String.valueOf(enterbillfloat + result)+"- RS");

        } else {
Toast.makeText(getApplicationContext(), "PLZ ENTER AMOUNT", Toast.LENGTH_LONG).show();
        }

    }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_height="match_parent"
    tools:context="com.example.viraj.tipcalculator.MainActivity">

    <EditText
        android:id="@+id/id_enteramount"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="16dp"
        android:ems="10"
        android:hint="Enter amount"
        android:inputType="number"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.503"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="32dp"
        android:text="SELECT TIP PERCENTAGE"
        android:textSize="24sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_enteramount" />

    <SeekBar
        android:id="@+id/id_seekbar"
        android:layout_width="297dp"
        android:layout_height="26dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="32dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.507"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView" />

    <TextView
        android:id="@+id/id_text_seekpercentage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="36dp"
        android:text="0%"
        android:textSize="24sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_seekbar" />

    <Button
        android:id="@+id/id_submitbutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="40dp"
        android:text="Button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_text_seekpercentage" />

    <TextView
        android:id="@+id/id_text_yourtip_is"
        android:layout_width="130dp"
        android:layout_height="32dp"
        android:layout_marginEnd="208dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="28dp"
        android:text="YOUR TIP IS"
        android:textSize="24sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_submitbutton" />

    <TextView
        android:id="@+id/id_text_totalamount"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="28dp"
        android:text="YOUR TOTAL AMOUNT IS "
        android:textSize="18sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.116"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_text_yourtip_is" />
</android.support.constraint.ConstraintLayout>

Share:

Wednesday, 22 November 2017

Radio Button direct Click

package com.example.viraj.radiobuton;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private RadioGroup radioGroup;
    private RadioButton radioButton;
   

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        radioGroup = (RadioGroup) findViewById(R.id.id_radioGroup);
       
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                radioButton = (RadioButton) findViewById(i);

                switch (radioButton.getId()) {
                    case R.id.id_yes: {
                        if (radioButton.isChecked()) {
                            Toast.makeText(getApplicationContext(), "YES I AM COMING", Toast.LENGTH_LONG).show();
                        }

                    }
                    break;
                    case R.id.id_no: {
                        if (radioButton.isChecked()) ;
                        {
                            Toast.makeText(getApplicationContext(), "NO I AM NOT COMING", Toast.LENGTH_LONG).show();
                        }
                    }
                    break;
                    case R.id.id_maybe: {
                        if (radioButton.isChecked()) ;
                        {
                            Toast.makeText(getApplicationContext(), "MAY BE COMING", Toast.LENGTH_LONG).show();
                        }
                    }
                    break;
                }
            }
        });


    }
}


xml file

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_height="match_parent"
    android:background="@drawable/one"
    tools:context="com.example.viraj.radiobuton.MainActivity">

    <RadioGroup
        android:id="@+id/id_radioGroup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="52dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView">

        <RadioButton
            android:id="@+id/id_yes"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="YES" />

        <RadioButton
            android:id="@+id/id_no"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="NO" />

        <RadioButton
            android:id="@+id/id_maybe"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="MAY BE" />
    </RadioGroup>

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="76dp"
        android:text="ARE YOU COMING ...."
        android:textColor="@color/colorPrimaryDark"
        android:textSize="24sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.503"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

Share:

colour converter app

package com.gohool.trymeoriginal.trymeoriginal;


import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.example.viraj.trymecolourconverter.R;

import java.util.Random;


public class MainActivity extends AppCompatActivity {

    private View windowView;
    private Button tryMeButton;
    private int[] colors;


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

        colors = new int[]{Color.CYAN, Color.GREEN, Color.RED, Color.BLUE, Color.BLACK, Color.DKGRAY,
                Color.LTGRAY, Color.MAGENTA, Color.YELLOW};

        windowView = findViewById(R.id.windowViewId);



        tryMeButton = (Button) findViewById(R.id.tryMeButton);
        tryMeButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //Array length
                int colorArrayLength = colors.length;

                Random random = new Random();
                int randomNum = random.nextInt(colorArrayLength);

                windowView.setBackgroundColor(colors[randomNum]);

                Log.d("Random", String.valueOf(randomNum));
            }
        });







    }
}

Share:

Tuesday, 21 November 2017

meter to inch conversion

package com.example.viraj.metertoinch;

import android.graphics.Color;
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.TextView;

public class MainActivity extends AppCompatActivity {
    private EditText entertext;
    private Button button;
    private TextView resultdisplay;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        entertext = (EditText) findViewById(R.id.id_enter_meter);
        resultdisplay = (TextView) findViewById(R.id.id_text_display);
        button = (Button) findViewById(R.id.id_button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //1m = (1/0.0254)″ = 39.37007874″
                //conversion data
                double multiplier = 39.37007874;
                double result = 0.0;
                //is se if txt not enter it display msg
                if (entertext.getText().toString().equals("")) {
                    resultdisplay.setText("PLZ ENTER VALID NO");
                    resultdisplay.setTextColor(Color.RED);
                } else {

                    double converter = Double.parseDouble(entertext.getText().toString());
                    result = converter * multiplier;
                    //resultdisplay.setText(Double.toString(result));
                    //decimal ke bad ko formate karne ke liye %.2f   % ke bad 2 decimal tak
                    resultdisplay.setText(String.format("%.2f", result) + "inch");
                }

            }
        });
    }
}

xml code

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_height="match_parent"

    tools:context="com.example.viraj.metertoinch.MainActivity">

    <EditText
        android:id="@+id/id_enter_meter"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="64dp"
        android:ems="10"
        android:hint="ENTER METER"
        android:inputType="textPersonName"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="64dp"
        android:text="METER TO INCH CONVERTER"

        android:textColor="@android:color/holo_green_dark"
        android:textSize="24sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/id_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="84dp"
        android:text="Button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_enter_meter" />

    <TextView
        android:id="@+id/id_text_display"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="60dp"
        android:text="o"
        android:textSize="30dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_button" />
</android.support.constraint.ConstraintLayout>


Share:

basic things java

https://github.com/FahdSheraz/androidOSource/blob/master/MMethods/src/com/gohooljava/com/Main.java

package com.gohooljava.com;

public class Main {

    public static void main(String[] args) {

   // write your code here
        myName("Paulo");

        int finalResult = addNums(4, 5);

        System.out.println( finalResult);


       System.out.println( fullName("George", "The Man"));

       System.out.println(showChar('D'));


    }

    //Method
     public static void myName(String mName) {

        System.out.println(mName);

     }

     // Return an integer

     public static int addNums(int a, int b) {
        int result;
        result = a + b;
      //  System.out.println(" Sum = "  + (a + b));

        return result ; // (a+b)
     }

     //Return a string

    public static String fullName(String firstName, String lastName){

        return firstName + " " + lastName;
    }

    // Return Character
    public static char showChar(char c) {
        return c;
    }



}

Share:

Monday, 20 November 2017

basic mathematical operation

https://github.com/FahdSheraz/androidOSource/blob/master/BasicOps/src/com/gohooljava/com/Main.java

package com.gohooljava.com;

public class Main {

    public static void main(String[] args) {

        /*
           for loop
           while loop
         */

        int i = 0;

        while (i < 5) {

            System.out.println(" Counting.. " + i);
            i++;

        }

       
            // Make sure to uncomment the code in order to be able to run the program successfully :)
       
//        for (int i = 0; i < 20; i++) {
//
//           //remainder ( %)
//            if ( i % 4 == 0) {
//
//                System.out.println( i + " is a multiple of 4 ");
//
//            }
//
//
//        }






  //Basic operations
        //Addition = +
        //Subtraction "-"
        //Multiplication "*"
        //Division "/"
        //Remainder = "what remains.." 4 % 2 = 0 because 2*2 = 4 and there's not remainder
        // 4%3 = 1

       int firstNum1 = 34;
       int secondNum2 = 3;
       System.out.println("The sum is +" (firstNum1 + secondNum2)); // Always add parenthesis in order for this to work

       //Subtraction
       System.out.println("The result is +" (firstNum1 - secondNum2)); // Always add parenthesis in order for this to work

        //Multiplication
       System.out.println("The result is +" (firstNum1 * secondNum2));

        //Division
       System.out.println("The result is +" (firstNum1 / secondNum2));

        // ==== Relational Operators ===
        /*
           - == comparison, not assignment
           - != NOT equal
           - > greater than
           - < less than
           - >= Greater than or equal
           - <= Less than or equal
           ==== Logical Operators =====
            - AND ( && ) == both "sides" need to be TRUE in order for the whole expression to return true
            - OR ( || )
            - NOT ( ! )
         */
//        double firstNum = 10;
//        double secondNum = 3;
//        double result = 0;
//
//        boolean isOld = true;
//        boolean isYoung = false;
//
//
//        if ( (isOld && !isYoung) && (firstNum < secondNum)  ) {
//
//            System.out.println("Horray!!");
//
//        }else {
//
//            System.out.println("Not right!");
//
//        }

//        result = firstNum % secondNum;
//
//        // If statements
//        if (firstNum <= secondNum) {
//
//
//            System.out.println("The remainder is " + result );
//
//        }else {
//
//            System.out.println("Numbers aren't equal");
//
//        }


    }
}
Share:

int float char double detail android


Share:

Sunday, 19 November 2017

list view android


<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_height="match_parent"

    android:background="#2196F3"
    tools:context="com.example.viraj.listview.MainActivity">

    <ListView
        android:id="@+id/id_list"
        android:layout_width="368dp"
        android:layout_height="495dp"
        android:divider="#f41331"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="8dp" />
</android.support.constraint.ConstraintLayout>



java code 

package com.example.viraj.listview;

import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity {
    private ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
      
  /// Get ListView object from xml
        listView = (ListView) findViewById(R.id.id_list);

        // Defined Array values to show in ListView
        String[] values1 = new String[]{"Android List View",
                "Adapter implementation",
                "Simple List View In Android",
                "Create List View Android",
                "Android Example",
                "List View Source Code",
                "List View Array Adapter",
                "Android Example List View"
        };
        // Define a new Adapter
        // First parameter - Context
        // Second parameter - Layout for the row
        // Third parameter - ID of the TextView to which the data is written
        // Forth - the Array of data
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, android.R.id.text1, values1);

        // Assign adapter to ListView
        listView.setAdapter(adapter);
        // ListView Item Click Listener
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                // ListView Clicked item index
                int itemPosition = position;

                // ListView Clicked item value
                String itemValue = (String) listView.getItemAtPosition(position);

                // Show Alert
                Toast.makeText(getApplicationContext(),
                        "Position :" + itemPosition + "  ListItem : " + itemValue, Toast.LENGTH_LONG)
                        .show();
            }
        });
    }
}

Share:

Sunday, 12 November 2017

intent data passing a to b activity

activity one .java page

package com.example.viraj.intent;

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

public class MainActivity extends AppCompatActivity {

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button button = (Button) findViewById(R.id.gotobutton);
        button.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
                Intent intent = new Intent(getApplicationContext(), Secondpage.class);
                intent.putExtra("keytosend", "dat kept here to send"); 
                intent.putExtra("value",123);
startActivity(intent); } }); } }

second activity page


package com.example.viraj.intent;
import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.widget.TextView;
public class Secondpage extends AppCompatActivity {
    private TextView textView;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_secondpage);
        textView = (TextView) findViewById(R.id.text_secondpage);
        Bundle name_bundel = getIntent().getExtras();

if (name_bundel != null) {
//ye string value ke liye he--------------------
            String name_string = name_bundel.getString("keytosend");
//ye integer type ki value ke liye he-------------------
            int intvalue=name_bundel.getInt("value");
           textView.setText("MESSAGE IS"+name_string+"values is "+intvalue);
} } }

Share:

INTENT BASIC

FIRST PAGE CODE

package com.example.viraj.intent;

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

public class MainActivity extends AppCompatActivity {

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
Button button=(Button)findViewById(R.id.gotobutton);
button.setOnClickListener(new View.OnClickListener() {
    @Override    public void onClick(View view) {
        Intent intent=new Intent(getApplicationContext(),Secondpage.class);
        startActivity(intent);
    }
});
    }
}


SECONDPAGECODE

package com.example.viraj.intent;

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

public class Secondpage extends AppCompatActivity {

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

Sunday, 5 November 2017

Tost in Android

Tost in Android 

package com.example.viraj.tosthe;

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

public class MainActivity extends AppCompatActivity {
private Button b1;
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        b1=(Button)findViewById(R.id.id_button);
        b1.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
                Toast.makeText(getApplicationContext(),"its working",Toast.LENGTH_LONG).show();
            }
        });
    }
}

Share:

Edit text in android

Edit text in android

package com.example.viraj.edittext;

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.TextView;

public class MainActivity extends AppCompatActivity {
private EditText e1;
private Button b1;
private TextView t1;
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        e1=(EditText)findViewById(R.id.id_edittext);
        b1=(Button)findViewById(R.id.id_button);
        t1=(TextView)findViewById(R.id.id_textdisplay);
        b1.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
                String myname=null;
                myname=e1.getText().toString();
                t1.setText(myname);
            }
        });
    }
}
xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_height="match_parent"
    tools:context="com.example.viraj.edittext.MainActivity">

    <EditText
        android:id="@+id/id_edittext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="64dp"
        android:ems="10"
        android:hint="ENTER YOUR Name"
        android:inputType="textPersonName"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.503"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/id_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="60dp"
        android:text="Button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_edittext" />

    <TextView
        android:id="@+id/id_textdisplay"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="80dp"
        android:text=""
        android:textSize="30dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_button" />

</android.support.constraint.ConstraintLayout>

Share:

APP RANDOM NO EVEREST NAME

APP HIGHEST MOUNTAIN NAME
JAVA FILE
package com.example.viraj.apphighestmountain;

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

import java.util.Random;

public class MainActivity extends AppCompatActivity {
private Button b1;
private TextView t1;
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        b1=(Button)findViewById(R.id.id_button);
        t1=(TextView)findViewById(R.id.id_text_generator);
        final String [] mountain={"rone","rtwo","rthree","rfour","rfive","rsix","rseven"};
        b1.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
                Random r1=new Random();
                int randomname=r1.nextInt(mountain.length);//mountin to length is 0 to all numbert1.setText(mountain[randomname]);//example mountain[2] where 2 - rthree             }
        });
    }
}

XML FILE

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_height="match_parent"
    tools:context="com.example.viraj.apphighestmountain.MainActivity">

    <Button
        android:id="@+id/id_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="100dp"
        android:text="RANDOM NAME GENERATE"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/id_text_generator"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="116dp"
        android:text="NAME "
        android:textSize="30dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/id_button" />

</android.support.constraint.ConstraintLayout>

Share:

Search This Blog

Popular Posts

Pages

how to make crores from 1 lakh in stock markets in 1 year

how to make crores from 1 lakh in stock markets in 1 year

Blogger Tutorials

Blogger Templates

Sample Text

Copyright © ANDROID TUTORIAL CODE | Powered by Blogger
Design by SimpleWpThemes | Blogger Theme by NewBloggerThemes.com & Distributed By Protemplateslab