Open top menu


Example-How to used RadioButton Control in android?


In this blog explain how to used RadioGroup in android. the Radiogroup is a radio button control, the control check which button is checked then previous button is automatic Uncheck with same group.


activity_main.xml
...................................................................................................................................................................
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    
android:layout_width="fill_parent"    
android:layout_height="fill_parent"   
android:orientation="vertical"    
android:background="#ffffff"     >
   
 <ImageView            
android:layout_width="wrap_content"            
android:layout_height="wrap_content"           
 android:id="@+id/imageView"            
android:layout_gravity="center"            
android:src="@drawable/my_heder_img"></ImageView>

    
<RadioGroup        
android:layout_width="wrap_content"        
android:layout_height="wrap_content"        
android:layout_marginTop="40dp"        
android:id="@+id/control"       
android:layout_gravity="center_vertical">
<RadioButton        
android:layout_width="wrap_content"        
android:layout_height="wrap_content"        
android:text="Lion"       
 android:id="@+id/radioButton"        />
<RadioButton        
android:layout_width="wrap_content"       
 android:layout_height="wrap_content"       
 android:text="Tigger"        
android:id="@+id/radioButton2"         />
<RadioButton       
android:layout_width="wrap_content"        
android:layout_height="wrap_content"        
android:text="Leopard"        
android:id="@+id/radioButton3"         />
    
<RadioButton        
android:layout_width="wrap_content"        
android:layout_height="wrap_content"        
android:text="Zabra"        
android:id="@+id/radioButton4"        />

<RadioButton        
android:layout_width="wrap_content"        
android:layout_height="wrap_content"        
android:text="Bear"        
android:id="@+id/radioButton5"        />
</RadioGroup>

<Button        
android:layout_width="wrap_content"        
android:layout_height="wrap_content"        
android:text="Select Animal Name"        
android:id="@+id/button"        
android:layout_marginTop="30dp"        
android:layout_gravity="center"/>


</LinearLayout>



...................................................................................................................................................................


MainActivity.java
...................................................................................................................................................................
public class MainActivity extends Activity  {
    private RadioGroup radioSexGroup;
    private RadioButton radioSexButton;
    private Button btnDisplay;

    @Override    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_main);

        radioSexGroup=(RadioGroup)findViewById(R.id.control);

        btnDisplay=(Button)findViewById(R.id.button);

        btnDisplay.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View v) {
                int selectedId=radioSexGroup.getCheckedRadioButtonId();
                radioSexButton=(RadioButton)findViewById(selectedId);
                Toast.makeText(MainActivity.this,radioSexButton.getText(),Toast.LENGTH_SHORT).show();
            }
        });

    }
}



...................................................................................................................................................................





Read more

Example-How to used SwitchButton in android studio?

The SwitchButton is a android widgets in android studio. switchbutton used two state ON and OFF.

setOnCheckedChangeListener()- User change button state onclick swicthButton . 

Then change state via this method

activity_main.xml
.................................................................................................................................................................
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    
android:layout_width="fill_parent"    
android:layout_height="fill_parent"   
android:orientation="vertical"    
android:background="#ffffff"     >
<ImageView            
android:layout_width="wrap_content"           
android:layout_height="wrap_content"            
android:id="@+id/imageView"            
android:layout_gravity="center"            
android:src="@drawable/my_heder_img"></ImageView>

<Switch            
android:layout_width="wrap_content"            
android:layout_height="wrap_content"            
android:id="@+id/switch1"            
android:layout_gravity="center_horizontal" />
             />
<TextView            
android:layout_width="200dp"            
android:layout_height="wrap_content"            
android:id="@+id/editText"            
android:layout_marginTop="30dp"            
android:layout_gravity="center_horizontal" />
<ImageView            
android:layout_width="wrap_content"            
android:layout_height="wrap_content"            
android:id="@+id/imagebuof"            
android:visibility="visible"            
android:layout_gravity="center"            
android:src="@drawable/bulb_off"></ImageView>
<ImageView       
 android:layout_width="wrap_content"       
 android:layout_height="wrap_content"        
android:id="@+id/imagebuon"        
android:layout_gravity="center"        
android:visibility="gone"        
android:src="@drawable/bulb_on"></ImageView>




</LinearLayout>










...................................................................................................................................................................



MainActivity.java.
...................................................................................................................................................................

public class MainActivity extends Activity  {
    Switch tgbutton;
    TextView edtext;
    ImageView imageoff,imageon;
    @Override    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);

        setContentView(R.layout.content_main);
        tgbutton = (Switch) findViewById(R.id.switch1);

        edtext=(TextView)findViewById(R.id.editText);
        imageoff=(ImageView)findViewById(R.id.imagebuof);
        imageon=(ImageView)findViewById(R.id.imagebuon);
        tgbutton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override            public void onCheckedChanged(CompoundButton buttonView,
                                         boolean isChecked) {

                if(isChecked){
                    edtext.setText("Switch ON");
                    imageoff.setVisibility(View.GONE);
                    imageon.setVisibility(View.VISIBLE);
                }else{
                    edtext.setText("Switch OFF");
                    imageoff.setVisibility(View.VISIBLE);
                    imageon.setVisibility(View.GONE);
                }

            }
        });

    }
}

...................................................................................................................................................................



Read more

How to uesd ToggleButton in android?


In this blog simple explain how to used ToggleButton.

setTextOff()--Means the ToggleButton is Checked.

setTextOn()--Means the ToggleButton is UnChecked.

activity_main.xml................................................................................................

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    
android:layout_width="fill_parent"    
android:layout_height="fill_parent"   
android:orientation="vertical"     >

<ImageView            
android:layout_width="wrap_content"            
android:layout_height="wrap_content"            
android:id="@+id/imageView"            
android:layout_gravity="center"            
android:src="@drawable/my_heder_img"             />

<ToggleButton            
android:layout_width="200dp"           
android:layout_height="wrap_content"            
android:text="New ToggleButton"           
android:layout_gravity="center"            
android:textOff="Show TextView"            
android:textOn="Hide TextView"            
android:id="@+id/toggleButton"             
 />



<EditText            
android:layout_width="200dp"            
android:layout_height="wrap_content"            
android:id="@+id/editText"            
android:visibility="gone"            
android:layout_marginTop="50dp"            
android:layout_gravity="center_horizontal" />


</LinearLayout>






MainActivity.java.................................................................................................

public class MainActivity extends Activity  {
    ToggleButton tgbutton;
    EditText edtext;
    @Override    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);

        setContentView(R.layout.activity_main);
        tgbutton = (ToggleButton) findViewById(R.id.toggleButton);

        edtext=(EditText)findViewById(R.id.editText);
        tgbutton.setOnClickListener(new View.OnClickListener() {

            @Override            public void onClick(View v) {
                // TODO Auto-generated method stub                if (tgbutton.isChecked()) {
                    edtext.setVisibility(View.VISIBLE);
                    Toast.makeText(getApplicationContext(),"SHOW",
                            Toast.LENGTH_SHORT).show();
                } else {

                    Toast.makeText(getApplicationContext(),"Hide",
                            Toast.LENGTH_SHORT).show();
                    edtext.setVisibility(View.GONE);
                }
            }
        });

    }
}






Read more



In this blog implement AutoCompleteTextView  in Android. The AutoCompleteTextView  is a suggestible and editable Text filed. Provided suggestion when user write the text in AutoCompleteTextView  the list of suggestion drop down as a menu then user choose and replace previous value..show this example and try ...


<AutoCompleteTextView    
android:layout_width="match_parent"    
android:layout_height="wrap_content"    
android:id="@+id/XYZ"    
android:textStyle="bold"    
android:hint="XYZ"    
android:layout_column="0"     /> 



Implement the full code....

activity_main.xml.
...............................................................................................
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"    
android:layout_width="fill_parent"    
android:layout_height="fill_parent"    >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="40px"
android:text="Write month and week name it will show month in autocomplete"
android:textColor="#000000"android:layout_marginLeft="10dip"
android:id="@+id/textView">
</TextView>
<AutoCompleteTextView           
android:layout_width="match_parent"            
android:layout_height="wrap_content"
android:id="@+id/Months"
android:textStyle="bold"
android:hint="Month"
android:layout_column="0"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="46dp"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/my_heder_img"
android:layout_alignParentBottom="true" 
android:layout_centerHorizontal="true" />
</RelativeLayout>

........................................................



MainActivity.Java.
.......................................................

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Toast;

public class MainActivity extends Activity implements AdapterView.OnItemClickListener, AdapterView.OnItemSelectedListener {

    AutoCompleteTextView textView;
    private ArrayAdapter<String> adapter;

    
    String monthsname[]={
            "Sunday", "Monday", "Tuesday", "Wednesday",
            "Thursday", "Friday", "Saturday","January", "February", "March", "April",
            "May", "June", "July", "August",
            "September", "October", "November", "December"    };


    @Override    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);


        setContentView(R.layout.activity_main);

        textView = (AutoCompleteTextView) findViewById(R.id.Months_and_week);
        adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, monthsname);
        textView.setThreshold(1);
        textView.setAdapter(adapter);
        textView.setOnItemSelectedListener(this);
        textView.setOnItemClickListener(this);

    }
    @Override    public void onItemSelected(AdapterView<?> arg0, View arg1, int position,
                               long arg3) {
    }

    @Override    public void onNothingSelected(AdapterView<?> arg0) {
        InputMethodManager imm = (InputMethodManager) getSystemService(
                INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);

    }

    @Override    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
      

       
        Toast.makeText(getBaseContext(), "Position:"+arg2+" Name:"+arg0.getItemAtPosition(arg2),
                Toast.LENGTH_LONG).show();

       

    }

}
.............................................................................................







Read more



 In this blog given Google Cloud DataStore Overview.Google Cloud Datastore is a No SQL document database built for automatic scaling, high performance, and ease of application development.

Atomic transactions. 

     Cloud Datastore can execute a set of operations where either all succeed.

 Reads and writes.

     Cloud Datastore runs in Google data centers, which use redundancy to minimize impact from points of failure.

High performance. 

     Cloud Datastore uses a distributed architecture to automatically manage scaling. Cloud Datastore uses a mix of indexes and query constraints so your queries scale with the size of your result set, not the size of your data set.

Flexible storage . 

     Cloud Datastore maps naturally to object-oriented and scripting languages, and is exposed to applications through multiple clients. It also provides a SQL-like 

Eventual consistency.

     Cloud Datastore ensures that entity lookups by key and ancestor queries always receive strongly consistent data. All other queries are eventually consistent. The consistency models allow your application to deliver a great user experience while handling large amounts of data and users.

Encryption at rest. 

     Cloud Datastore automatically encrypts all data before it is written to disk and automatically decrypts the data when read by an authorized user. For more information, see 


Read more