Monday, 23 September 2019

Android Programming MENU Concept

D:\androidoptionmenuchan\app\src\main\res\layout\activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

   
xmlns:app="http://schemas.android.com/apk/res-auto"
   
android:layout_width="match_parent"
   
android:layout_height="match_parent"
   
android:orientation="vertical"
   
>
  

    <
TextView
       
android:id="@+id/txt1"
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="CONTEXT MENU  FOR BIRDS LIST"
       
android:paddingBottom="30dp"
       
android:textAllCaps="true"
       
android:textSize="20sp"
       
/>
    <
Button
       
android:id="@+id/button"
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:layout_alignParentStart="true"
       
android:layout_alignParentTop="true"
       
android:layout_marginTop="181dp"
       
android:onClick="popup1"
       
android:text=" POPUP MENU FOR BIRDS LIST "
       
android:textAllCaps="true" />

   


</
RelativeLayout>


_________________________________________________________
D:\androidoptionmenuchan\app\src\main\res\menu\menu_file.xml

<?xml version="1.0" encoding="utf-8"?>

<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:id="@+id/birds"

        android:title="Click to see sub items"

        android:icon="@drawable/allbirds" >



        <!-- "item" submenu -->

        <menu>

            <item android:id="@+id/peacock"

                android:title="Peacock"

                android:icon="@drawable/peacock"/>

            <item android:id="@+id/parrot"

                android:title="Parrot"

                android:icon="@drawable/parrot" />

            <item android:id="@+id/duck"

                android:title="Duck"

                android:icon="@drawable/duck" />



        </menu>

    </item>

</menu>

D:\androidoptionmenuchan\app\src\main\res\menu\menu_file1.xml

<?xml version="1.0" encoding="utf-8"?>

<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:id="@+id/gforest"

        android:title=" Gir Forest"

        android:icon="@drawable/allbirds" >



                   <item android:id="@+id/sforest"

                android:title="Sundarban Forest "

                />

            <item android:id="@+id/vforest"

                android:title="Vandalur Forest"

                 />

            <item android:id="@+id/kforest"

                android:title="Kaziranga Forest "

                 />





    </item>

</menu>

D:\androidoptionmenuchan\app\src\main\java\com\ldc\androidoptionmenuchan\MainActivity.java

package com.ldc.androidoptionmenuchan;



import android.app.Activity;

import android.os.Bundle;

import android.view.ContextMenu;

import android.view.Menu;

import android.view.MenuInflater;

import android.view.MenuItem;

import android.view.View;

import android.widget.ImageButton;

import android.widget.ImageView;

import android.widget.PopupMenu;



import android.widget.TextView;

import android.widget.Toast;





public class MainActivity extends Activity implements PopupMenu.OnMenuItemClickListener {

ImageView imgv1;

ImageButton imgb1;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        //imgb1=(ImageButton) findViewById(R.id);

        //registerForContextMenu((ImageView)findViewById(R.id.imageView));

       // imgv1=(ImageView) findViewById(R.id.imgvw1);





        //Registering for Context Menu

        registerForContextMenu((TextView)findViewById(R.id.txt1));



    }



    @Override

    public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfor) {

        super.onCreateContextMenu(menu, view, menuInfor);



        MenuInflater menin = getMenuInflater();

        menin.inflate(R.menu.menu_file,menu);

    }





    @Override

    public boolean onContextItemSelected(MenuItem m_item) {

        switch (m_item.getItemId()){

            case R.id.birds:

                Toast.makeText(this,"BIRDS LIST CONTEXT MENU",Toast.LENGTH_SHORT).show();

                break;

            case R.id.peacock:

                Toast.makeText(this,"I Love Dancing During  Raining ",Toast.LENGTH_SHORT).show();

                break;

            case R.id.parrot:

                Toast.makeText(this,"I Love Eating of Nuts",Toast.LENGTH_SHORT).show();

                break;

            case R.id.duck:

                Toast.makeText(this,"I Love Swimming ",Toast.LENGTH_SHORT).show();

                break;

        }

        return true;



    }



    @Override

    public boolean onCreateOptionsMenu(Menu menu) {



        MenuInflater menin1 = getMenuInflater();

        menin1.inflate(R.menu.menu_file, menu);

        return true;

    }





    @Override

    public boolean onOptionsItemSelected(MenuItem m_item) {



        switch (m_item.getItemId()) {

            case R.id.birds :  Toast.makeText(this, "Cicked Main Menu - Birds", Toast.LENGTH_SHORT).show();

                 break;

            case R.id.peacock:

                Toast.makeText(this, "   Beautiful Peackcock", Toast.LENGTH_SHORT).show();

                break;

            case R.id.parrot:

                Toast.makeText(this, " Gracyful  Parrot ", Toast.LENGTH_SHORT).show();

                break;

            case R.id.duck:

                Toast.makeText(this, "Lovely Duck", Toast.LENGTH_SHORT).show();

                break;

        }

        return true;

    }





    public void popup1(View view1) {

        PopupMenu popup = new PopupMenu(this, view1);

        popup.setOnMenuItemClickListener(this);

        MenuInflater menuin2 = getMenuInflater();

        menuin2.inflate(R.menu.menu_file1, popup.getMenu());

        popup.show();



    }





    @Override

    public boolean onMenuItemClick(MenuItem m_item) {

        switch (m_item.getItemId()) {

            case R.id.gforest:

                Toast.makeText(this, "Gir Forest  in Gujarat", Toast.LENGTH_SHORT).show();



                break;

            case R.id.sforest:

                Toast.makeText(this, "Sundarban Forest in West Bangal ", Toast.LENGTH_SHORT).show();

                break;

            case R.id.kforest:

                Toast.makeText(this, "Kaziranga Forest  in Chennai", Toast.LENGTH_SHORT).show();

                break;

            case R.id.vforest:

                Toast.makeText(this, "Vandalure Forest in Assam", Toast.LENGTH_SHORT).show();

                break;

        }

        return true;

    }

}

__________________________________________________________________________

Wednesday, 28 August 2019

Android Programming - Webview

 D:\MyApplication9\app\src\main\res\layout\activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">


    <WebView
        android:id="@+id/W1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</RelativeLayout>


**************************************************************************
D:\MyApplication9\app\src\main\java\com\ldc\myapplication\MainActivity.java

package com.ldc.myapplication;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
public class MainActivity extends Activity {
WebView wv1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        wv1=(WebView) findViewById(R.id.W1);
        wv1.loadUrl("https://jchanpro.blogspot.com/");
    }
}





**************************************************************************

D:\MyApplication9\app\src\main\AndroidManifest.xml


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.ldc.myapplication">
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Tuesday, 27 August 2019

Android Programming Simplified one

D:\chandreadymadeshop\app\src\main\res\layout\activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"    
android:layout_width="match_parent"   
 android:layout_height="match_parent"   
  android:background="@drawable/chandra">
    <LinearLayout      
   android:layout_width="match_parent"    
       android:layout_height="match_parent"   
         android:orientation="vertical">

        <TextView         
  android:id="@+id/TV1" 
  android:layout_width="wrap_content"  
 android:layout_height="wrap_content"  
  android:text="Select Whatever you Want !!"     
  android:textColor="@android:color/holo_red_dark"   
  android:textSize="20sp" />


        <CheckBox           
    android:id="@+id/CB1"          
    android:layout_width="wrap_content"          
    android:layout_height="wrap_content"           
    android:checked="false"           
    android:text="Silk Saree"           
    android:textColor="#F00" />

        <CheckBox           
  android:id="@+id/CB2"           
  android:layout_width="wrap_content"           
  android:layout_height="wrap_content"          
   android:checked="false"          
    android:text="Synthetic Saree"           
    android:textColor="#F0F" />

        <CheckBox           
  android:id="@+id/CB3"           
  android:layout_width="wrap_content"           
  android:layout_height="wrap_content"           
  android:checked="false"           
  android:text="Cotton Saree"           
  android:textColor="#F00F" />
        <CheckBox           
  android:id="@+id/CB4"           
  android:layout_width="wrap_content"           
  android:layout_height="wrap_content"           
  android:checked="false"           
  android:text="Jute Saree"           
  android:textColor="#ff00" />
        <Button           
  android:layout_width="314dp"           
  android:layout_height="wrap_content"           
  android:text="PRESS IT"           
  android:id="@+id/btn"           
  android:background="#f8f40b"           
  android:textColor="#fd0707"/>
    </LinearLayout>
</ScrollView>
-----------------------------------------------------------------------------
D:\chandreadymadeshop\app\src\main\java\com\ldc\chandreadymadeshop\MainActivity.java
 
 
package com.ldc.chandreadymadeshop;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
    Button btn;
    CheckBox cb1, cb2, cb3,cb4;

    TextView v1;
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        cb1=(CheckBox) findViewById(R.id.CB1);
        cb2=(CheckBox) findViewById(R.id.CB2);
        cb3=(CheckBox) findViewById(R.id.CB3);
        cb4=(CheckBox) findViewById(R.id.CB4);
        btn=(Button) findViewById(R.id.btn);
        v1=(TextView) findViewById(R.id.TV1);

        btn.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
                String txt=" ";
                if(cb1.isChecked() == true )
                    txt=(String)cb1.getText();
                if(cb2.isChecked() == true )
                    txt=txt+", "+(String)cb2.getText();
                if(cb3.isChecked() == true )
                    txt=txt+"  , "+(String)cb3.getText();
                if(cb4.isChecked() == true )
                    txt=txt+"  , "+(String)cb4.getText();
                v1.setText("You have Selected "+txt);

                if(cb1.isChecked() == false && cb2.isChecked()==false && cb3.isChecked()==false && cb4.isChecked()==false)

                {
                    Toast.makeText(getBaseContext(),"OOPS! you haven`t selected anythng (: (: ",Toast.LENGTH_LONG).show();
                    v1.setText("You haven't Selected (: (; (: "+txt);
                }



            }
        });
    }
}
----------------------------------------------------------------------------------------
 

Monday, 26 August 2019

Android Programming - CheckBox

D:\chandreadymadeshop\app\src\main\res\layout\activity_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" 
 android:background="@drawable/chandra">
 
 <LinearLayout         
android:layout_width="match_parent" 
 android:layout_height="match_parent" 
 android:orientation="vertical">

        <TextView 
 android:id="@+id/TV1" 
 android:layout_width="wrap_content"             
android:layout_height="wrap_content" 
 android:text="Select Whatever you Want !!"             
android:textColor="@android:color/holo_red_dark" 
 android:textSize="40sp" />

        <CheckBox             
android:id="@+id/CB1" 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:checked="false" 
 android:text="Silk Saree" 
 android:textColor="@android:color/holo_orange_dark" />

        <CheckBox 
 android:id="@+id/CB2"             
android:layout_width="wrap_content"             
android:layout_height="wrap_content" 
 android:checked="false"             
android:text="Synthetic Saree" 
 android:textColor="@android:color/holo_green_dark" />

        <CheckBox 
 android:id="@+id/CB3" 
 android:layout_width="wrap_content" 
 
 android:layout_height="wrap_content"             
android:checked="false" 
 android:text="Cotton Saree" 
 android:textColor="@android:color/holo_blue_dark" />
 
 <CheckBox 
 android:id="@+id/CB4"             
android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:checked="false" 
 android:text="Jute Saree" 
 android:textColor="@android:color/holo_red_light" />
 
 <Button 
 android:layout_width="314dp"             
android:layout_height="wrap_content"             
android:text="PRESS IT"             
android:id="@+id/btn" 
 android:background="#f8f40b" 
 android:textColor="#fd0707"/>
    </LinearLayout>
</ScrollView>
-----------------------------------------------------------------------------------------
D:\chandreadymadeshop\app\src\main\java\com\ldc\chandreadymadeshop\MainActivity.java 

package com.ldc.chandreadymadeshop;



import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;

public class MainActivity extends Activity {
    Button btn;
    CheckBox cb1, cb2, cb3,cb4;
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        cb1=(CheckBox) findViewById(R.id.CB1);
        cb2=(CheckBox) findViewById(R.id.CB2);
        cb3=(CheckBox) findViewById(R.id.CB3);
        cb4=(CheckBox) findViewById(R.id.CB4);
        btn=(Button) findViewById(R.id.btn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
                if(cb1.isChecked() == true && cb2.isChecked()== false && cb3.isChecked()==false && cb4.isChecked()==false)
                    Toast.makeText(getBaseContext(),"Silk Saree", Toast.LENGTH_LONG).show();
                if(cb1.isChecked() == false && cb2.isChecked()==true && cb3.isChecked()==false && cb4.isChecked()==false)
                    Toast.makeText(getBaseContext(),"Synthetic  Saree",Toast.LENGTH_LONG).show();
                if(cb1.isChecked() == false && cb2.isChecked()==false && cb3.isChecked()==true && cb4.isChecked()==false)
                    Toast.makeText(getBaseContext(),"Cotton Saree",Toast.LENGTH_LONG).show();
                if(cb1.isChecked() == false && cb2.isChecked()==false && cb3.isChecked()== false && cb4.isChecked()==true)
                    Toast.makeText(getBaseContext(),"Jute Saree ",Toast.LENGTH_LONG).show();
                if(cb1.isChecked() == true && cb2.isChecked()==true && cb3.isChecked()== false && cb4.isChecked()==false)
                    Toast.makeText(getBaseContext(),"Silk Sree Cotton Saree  ",Toast.LENGTH_LONG).show();
                if(cb1.isChecked() == true && cb2.isChecked()==true && cb3.isChecked()== true && cb4.isChecked()==false)
                    Toast.makeText(getBaseContext(),"Silk Sree Cotton Saree and Synthetic Saree ",Toast.LENGTH_LONG).show();
                if(cb1.isChecked() == true && cb2.isChecked()==true && cb3.isChecked()== true && cb4.isChecked()==true)
                    Toast.makeText(getBaseContext(),"Silk Sree Cotton Saree , Synthetic Saree and Jute Saree",Toast.LENGTH_LONG).show();

                if(cb1.isChecked() == false && cb2.isChecked()==false && cb3.isChecked()==false && cb4.isChecked()==false)
                    Toast.makeText(getBaseContext(),"OOPS! you haven`t selected anythng (: (: ",Toast.LENGTH_LONG).show();


            }
        });
    }
}
------------------------------------------------------------------------------------