Adding RadioButtons in Android - android

I want to add radio buttons such that only one of them is selected at a time among 4 buttons and I want to place them as:
RadioButton1 RadioButton2
RadioButton3 RadioButton4
I am trying the following code but 1&2 forms a grp and 3&4 forms a different grp and there are two value selected a time. Can anyone check it and share the correct way to do it?
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/apple" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
>
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/rdogrp_main"
android:orientation="vertical"
>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/rdogrp1"
android:orientation="horizontal"
>
<RadioButton
android:id="#+id/RadioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Orange"
android:textColor="#000000"
/>
<RadioButton
android:id="#+id/RadioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:text="BlueBerry"
android:textColor="#000000"
/>
</RadioGroup>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/rdogrp2"
android:orientation="horizontal"
>
<RadioButton
android:id="#+id/RadioButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Apple "
android:textColor="#000000"
/>
<RadioButton
android:id="#+id/RadioButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:text="Santra :P"
android:textColor="#000000"
/>
</RadioGroup>
</RadioGroup>
</LinearLayout>

Ok I find a solution for you:
I know it is not the best solution but it works! :)
Just copy the xml file and activity code bellow:
Activity:
package com.example.stackoverflow;
import android.os.Bundle;
import android.app.Activity;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.RadioButton;
public class MainActivity extends Activity {
private static String TAG = "MainActivity";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final RadioButton radiobutton1 = (RadioButton) findViewById(R.id.RadioButton1);
final RadioButton radiobutton2 = (RadioButton) findViewById(R.id.RadioButton2);
final RadioButton radiobutton3 = (RadioButton) findViewById(R.id.RadioButton3);
final RadioButton radiobutton4 = (RadioButton) findViewById(R.id.RadioButton4);
radiobutton1.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
radiobutton1.setChecked(true);
radiobutton2.setChecked(false);
radiobutton3.setChecked(false);
radiobutton4.setChecked(false);
return true;
}
});
radiobutton2.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
radiobutton2.setChecked(true);
radiobutton1.setChecked(false);
radiobutton3.setChecked(false);
radiobutton4.setChecked(false);
return true;
}
});
radiobutton3.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
radiobutton3.setChecked(true);
radiobutton1.setChecked(false);
radiobutton2.setChecked(false);
radiobutton4.setChecked(false);
return true;
}
});
radiobutton4.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
radiobutton4.setChecked(true);
radiobutton1.setChecked(false);
radiobutton2.setChecked(false);
radiobutton3.setChecked(false);
return true;
}
});
}
}
activity_main.xml :
<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" >
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#FFDDDDDD" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioGroup
android:id="#+id/rdogrp1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/RadioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Orange"
android:textColor="#000000" />
<RadioButton
android:id="#+id/RadioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:text="BlueBerry"
android:textColor="#000000" />
</RadioGroup>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioGroup
android:id="#+id/rdogrp2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/RadioButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Apple "
android:textColor="#000000" />
<RadioButton
android:id="#+id/RadioButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:text="Santra :P"
android:textColor="#000000" />
</RadioGroup>
</TableRow>
</TableLayout>
</RelativeLayout>

For that you need to create only one RadioGroup and add four different RadioButton.
And for adding UI refer this url : Manage Layout Inside a Horizontal Oriented Radiogroup .
I hope this will help you.

Try Like this..
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RadioGroup
android:id="#+id/rdogrp_main"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/RadioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.20"
android:text="India"
android:textColor="#000000" />
<RadioButton
android:id="#+id/RadioButton2"
android:layout_width="74dp"
android:layout_height="wrap_content"
android:layout_weight="0.57"
android:text="Austraila"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/RadioButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="Srilanka "
android:textColor="#000000" />
<RadioButton
android:id="#+id/RadioButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.48"
android:text="SouthAfrica"
android:textColor="#000000" />
</LinearLayout>
</RadioGroup>
</LinearLayout>
Let me know if you solve the problem...

Related

No Action onRadioButton click after reset

I'm an Android beginner and I have a little problem.
I have 2 radioButtons titled "Yes" and "No", 4 editTexts which are disabled and a button titled "Reset All".
Now, when I select the "No" radioButton, editTexts 1 and 2 become enabled and 1 gains focus. This is the desired behaviour. But When I select "Reset All" and again repeat the procedure, only editText 2 gets enabled and the "No" radioButton is still unchecked.
Following is my code:
MainActivity.java
package com.example.chris.myapplication;
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.RadioButton;
public class MainActivity extends AppCompatActivity {
EditText e1;
EditText e2;
EditText e3;
EditText e4;
RadioButton yes;
RadioButton no;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e1 = (EditText)findViewById(R.id.e1);
e2 = (EditText)findViewById(R.id.e2);
e3 = (EditText)findViewById(R.id.e3);
e4 = (EditText)findViewById(R.id.e4);
yes = (RadioButton)findViewById(R.id.yes);
no = (RadioButton)findViewById(R.id.no);
}
public void onClickreset(View v){
yes.setChecked(false);
no.setChecked(false);
e1.setEnabled(false);
e2.setEnabled(false);
e3.setEnabled(false);
e1.setText("");
e2.setText("");
e3.setText("");
e4.setText("");
};
public void onRadioButtonClicked(View v)
{
boolean checked = ((RadioButton) v).isChecked();
switch(v.getId()){
case R.id.yes:
if(checked)
e1.setEnabled(false);
e2.setEnabled(false);
e3.setEnabled(true);
e3.requestFocus();
break;
case R.id.no:
if(checked)
e1.setEnabled(true);
e2.setEnabled(true);
e2.requestFocus();
e2.clearFocus();
e3.setEnabled(false);
break;
}
}
}
activity_main.xml
<?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:id="#+id/LL"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.chris.myapplication.MainActivity">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="*"
android:stretchColumns="*">
<!-- Row 1 Starts From Here -->
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="3"
android:gravity="center"
android:orientation="horizontal">
<RadioButton
android:id="#+id/yes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="1dp"
android:checked="false"
android:onClick="onRadioButtonClicked"
android:text="yes" />
<RadioButton
android:id="#+id/no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:checked="false"
android:onClick="onRadioButtonClicked"
android:text="no" />
</RadioGroup>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:id="#+id/t1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:text="1:"
android:textColor="#000000" />
<EditText
android:id="#+id/e1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:enabled="false"
android:inputType="numberDecimal"
android:textColor="#000000" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:id="#+id/t2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:text="2:"
android:textColor="#000000" />
<EditText
android:id="#+id/e2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:enabled="false"
android:inputType="numberDecimal"
android:textColor="#000000" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:id="#+id/t3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:text="3:"
android:textColor="#000000" />
<EditText
android:id="#+id/e3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:enabled="false"
android:inputType="numberDecimal"
android:textColor="#000000" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:id="#+id/t4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:text="4:"
android:textColor="#000000" />
<EditText
android:id="#+id/e4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:enabled="false"
android:inputType="numberDecimal"
android:textColor="#000000" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="30dp" />
<Button
android:id="#+id/reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_span="3"
android:gravity="center"
android:onClick="onClickreset"
android:text="Reset"
android:textAllCaps="false"
android:textColor="#000000"
android:textStyle="normal" />
</TableLayout>
</LinearLayout>
It's better to use RadioGroup.OnCheckedChangeListener, first of all, get rid of android:onClick attributes and assign an id to RadioGroup in XML:
<RadioGroup
android:id="#+id/yes_no_radio_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="3"
android:gravity="center"
android:orientation="horizontal">
<RadioButton
android:id="#+id/yes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="1dp"
android:checked="false"
android:text="yes" />
<RadioButton
android:id="#+id/no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:checked="false"
android:text="no" />
</RadioGroup>
Then make your Activity implements RadioGroup.OnCheckedChangeListener and move there code from onRadioButtonClicked(View v) method:
public class MainActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener {
//Some activity code
#Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
switch (radioGroup.getCheckedRadioButtonId()) {
case R.id.yes: //Not needed to
e1.setEnabled(false); //which RadioButton clicked
e2.setEnabled(false);
e3.setEnabled(true);
e3.requestFocus();
break;
case R.id.no:
e1.setEnabled(true);
e2.setEnabled(true);
e2.requestFocus();
e2.clearFocus();
e3.setEnabled(false);
break;
}
}
}
Then, assign OnCheckedChangeListener with RadioGroup:
yesNoGroup = findViewById(R.id.radio_group);
yesNoGroup.setOnCheckedChangeListener(this);
And change:
yes.setChecked(false);
no.setChecked(false);
To
yesNoGroup.clearCheck();

Android: TextView alignment with respect to RadioGroup

Hi i'm trying to implement the following design (RadioGroup is parallel to TextView of rignt side)
for this requirement i wrote the bellow xml code
<RelativeLayout
android:id="#+id/rl_group_create_group_privacy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rl_group_create_group_icon"
android:layout_marginTop="10dp"
android:background="#drawable/rl_bg_board_group_create_group"
android:padding="10dp" >
<TextView
android:id="#+id/tv_group_create_group_privacy"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:text="#string/group_create_new_group_privacy"
android:textColor="#color/Black"
android:textSize="15sp" />
<RadioGroup
android:id="#+id/rg_group_create_group_privacy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/tv_group_create_group_privacy"
android:orientation="vertical" >
<RadioButton
android:id="#+id/rb_group_create_group_public"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="false"
android:text="#string/group_create_new_group_public"
android:textSize="12sp" />
<RadioButton
android:id="#+id/rb_group_create_group_closed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:checked="false"
android:text="#string/group_create_new_group_closed"
android:textSize="12sp" />
<RadioButton
android:id="#+id/rb_group_create_group_secret"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="19dp"
android:layout_weight="1"
android:checked="false"
android:text="#string/group_create_new_group_secret"
android:textSize="12sp" />
</RadioGroup>
<RelativeLayout
android:id="#+id/rl_group_create_group_privacy_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/rg_group_create_group_privacy"
android:background="#color/White" >
<TextView
android:id="#+id/tv_group_create_group_public_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="#string/group_create_new_group_public_desc"
android:textColor="#color/Black"
android:textSize="12sp" />
<TextView
android:id="#+id/tv_group_create_group_closed_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_group_create_group_public_desc"
android:layout_marginTop="10dp"
android:text="#string/group_create_new_group_closed_desc"
android:textColor="#color/Black"
android:textSize="12sp" />
<TextView
android:id="#+id/tv_group_create_group_secret_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_group_create_group_closed_desc"
android:layout_marginTop="10dp"
android:text="#string/group_create_new_group_secret_desc"
android:textColor="#color/Black"
android:textSize="12sp" />
</RelativeLayout>
</RelativeLayout>
But it changing the alignment according to the device like the following picture (Some times radio button at middle of textView and some times at starting of textView and some more times at end of textView). By implementing the design in layout-large, layout-small, layout-xlarge we can achieve this some how but i don't want to follow. So, how to implement first image design without following layout-large, layout-small, layout-xlarge
I hope this may helpful to you
<LinearLayout
android:id="#+id/rl_group_create_group_privacy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rl_group_create_group_icon"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:padding="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top">
<TextView
android:id="#+id/tv_group_create_group_privacy"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:gravity="center"
android:padding="5dp"
android:text="Privacy"
android:textColor="#000000"
android:textSize="15sp" />
<RadioButton
android:id="#+id/rb_group_create_group_public"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/tv_group_create_group_privacy"
android:checked="false"
android:gravity="center|start"
android:text="Public"
android:textSize="12sp" />
<TextView
android:id="#+id/tv_group_create_group_public_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/rb_group_create_group_public"
android:padding="5dp"
android:text="group_create_new_group_public_desc"
android:textColor="#000000"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top">
<RadioButton
android:id="#+id/rb_group_create_group_closed"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp"
android:checked="false"
android:text="Closed"
android:textSize="12sp" />
<TextView
android:id="#+id/tv_group_create_group_closed_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/rb_group_create_group_closed"
android:padding="5dp"
android:text="group_create_new_group_closed_desc"
android:textColor="#000000"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_group_create_group_privacy_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top">
<RadioButton
android:id="#+id/rb_group_create_group_secret"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp"
android:checked="false"
android:text="Secret"
android:textSize="12sp" />
<TextView
android:id="#+id/tv_group_create_group_secret_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/rb_group_create_group_secret"
android:padding="5dp"
android:text="group_create_new_group_secret_desc"
android:textColor="#000000"
android:textSize="12sp" />
</RelativeLayout>
</LinearLayout>
In Activity
final RadioButton rbPublic = (RadioButton) findViewById(R.id.rb_group_create_group_public);
final RadioButton rbCloses = (RadioButton) findViewById(R.id.rb_group_create_group_closed);
final RadioButton rbSecret = (RadioButton) findViewById(R.id.rb_group_create_group_secret);
rbPublic.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
rbCloses.setChecked(!isChecked);
rbSecret.setChecked(!isChecked);
}
}
});
rbCloses.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
rbPublic.setChecked(!isChecked);
rbSecret.setChecked(!isChecked);
}
}
});
rbSecret.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
rbCloses.setChecked(!isChecked);
rbPublic.setChecked(!isChecked);
}
}
});

How to uncheck radio button in different listview in same layout.?

I have cleared many problems about radio buttons but this was in my mind since many days. I have 5 radio buttons in different list view please tell me how to uncheck any radio button while accessing other and get the value of selected radio button.
following are the codes.
custom_dialogue.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="wrap_content"
android:layout_height="wrap_content"
tools:ignore="HardcodedText,RtlHardcoded,NestedWeights,UselessParent" >
<LinearLayout
android:layout_width="350dp"
android:layout_height="400dp"
android:background="#000000"
android:orientation="vertical"
android:weightSum="8" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#E3EBED"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:text="Screen timeout"
android:textColor="#449BA4"
android:textSize="21sp" />
</LinearLayout>
<RadioGroup
android:id="#+id/rg_all"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#F5F5F5"
android:orientation="horizontal"
android:weightSum="10" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_weight="9"
android:text="15 seconds"
android:textColor="#000000"
android:textSize="18sp"
tools:ignore="HardcodedText" />
<RadioButton
android:id="#+id/rb_15sec"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#F5F5F5"
android:orientation="horizontal"
android:weightSum="10" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_weight="9"
android:text="30 seconds"
android:textColor="#000000"
android:textSize="18sp"
tools:ignore="HardcodedText" />
<RadioButton
android:id="#+id/rb_30sec"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#F5F5F5"
android:orientation="horizontal"
android:weightSum="10" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_weight="9"
android:text="1 minute"
android:textColor="#000000"
android:textSize="18sp" />
<RadioButton
android:id="#+id/rb_1min"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#F5F5F5"
android:orientation="horizontal"
android:weightSum="10" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_weight="9"
android:text="2 minutes"
android:textColor="#000000"
android:textSize="18sp" />
<RadioButton
android:id="#+id/rb_2min"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#F5F5F5"
android:orientation="horizontal"
android:weightSum="10" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_weight="9"
android:text="5 minutes"
android:textColor="#000000"
android:textSize="18sp" />
<RadioButton
android:id="#+id/rb_5min"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:checked="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#F5F5F5"
android:orientation="horizontal"
android:weightSum="10" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_weight="9"
android:text="10 minutes"
android:textColor="#000000"
android:textSize="18sp" />
<RadioButton
android:id="#+id/rb_10min"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
</LinearLayout>
</RadioGroup>
<LinearLayout
android:id="#+id/ll_cancel"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#C9DCE0"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Cancel"
android:textColor="#000000"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
CustomDialogue.java
package com.example.coustomdialogue;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
import android.widget.Toast;
public class CustomDialogue extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_dialogue);
final RadioGroup rg = (RadioGroup) findViewById(R.id.rg_all);
final RadioButton rb1 = (RadioButton)findViewById(R.id.rb_10min);
final RadioButton rb2 = (RadioButton)findViewById(R.id.rb_15sec);
final RadioButton rb3 = (RadioButton)findViewById(R.id.rb_1min);
final RadioButton rb4 = (RadioButton)findViewById(R.id.rb_2min);
final RadioButton rb5 = (RadioButton)findViewById(R.id.rb_30sec);
final RadioButton rb6 = (RadioButton)findViewById(R.id.rb_5min);
rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if(checkedId == R.id.rb_10min){
rg.clearCheck();
rb2.setChecked(false);
rb3.setChecked(false);
rb4.setChecked(false);
rb5.setChecked(false);
rb6.setChecked(false);
}else if(checkedId == R.id.rb_15sec){
rg.clearCheck();
rb1.setChecked(false);
rb3.setChecked(false);
rb4.setChecked(false);
rb5.setChecked(false);
rb6.setChecked(false);
}else if(checkedId == R.id.rb_1min){
rg.clearCheck();
rb2.setChecked(false);
rb4.setChecked(false);
rb1.setChecked(false);
rb5.setChecked(false);
rb6.setChecked(false);
}else if(checkedId == R.id.rb_2min){
rg.clearCheck();
rb2.setChecked(false);
rb3.setChecked(false);
rb5.setChecked(false);
rb1.setChecked(false);
rb6.setChecked(false);
}else if(checkedId == R.id.rb_30sec){
rg.clearCheck();
rb2.setChecked(false);
rb3.setChecked(false);
rb4.setChecked(false);
rb6.setChecked(false);
rb1.setChecked(false);
}else{
rg.clearCheck();
rb2.setChecked(false);
rb2.setChecked(false);
rb3.setChecked(false);
rb4.setChecked(false);
rb5.setChecked(false);
rb1.setChecked(false);
}
}
});
}
}
I got the real Answer for the following I solved my problem as I used a Click event on every radio button. Whenever I click on the radio Button at that time i change the checked to uncheck if any. No need to use RadioGroup.
Hope this helped you all.

Custom Alignment of RadioButtons in Android

I have 4 RadioButtons (part of same RadioGroup) and I want to align them like this :
Code I am using is :
<RadioGroup
android:id="#+id/add_reminder_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="#dimen/zero"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >
<RadioButton
android:id="#+id/add_reminder_daily"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/add_reminder_daily" />
<RadioButton
android:id="#+id/add_reminder_weekly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/add_reminder_weekly" />
</LinearLayout>
<LinearLayout
android:layout_width="#dimen/zero"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >
<RadioButton
android:id="#+id/add_reminder_monthly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/add_reminder_monthly" />
<RadioButton
android:id="#+id/add_reminder_yearly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/add_reminder_yearly" />
</LinearLayout>
</RadioGroup>
But by using this code, RadioGroup loses its property and all the RadioButtons can be checked at same time.
Any idea how RadioGroup can retain its property using this type of alignment ?
You can Try This....
first declare all radio button
r1=(RadioButton) findViewById(R.id.add_reminder_daily);
r2=(RadioButton) findViewById(R.id.add_reminder_weekly);
r3=(RadioButton) findViewById(R.id.add_reminder_monthly);
r4=(RadioButton) findViewById(R.id.add_reminder_yearly);
now on - onclick listner do
r1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
r2.setChecked(false);
r3.setChecked(false);
r4.setChecked(false);
}
});
r2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
r1.setChecked(false);
r3.setChecked(false);
r4.setChecked(false);
}
});
r3.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
r2.setChecked(false);
r1.setChecked(false);
r4.setChecked(false);
}
});
r4.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
r2.setChecked(false);
r3.setChecked(false);
r1.setChecked(false);
}
});
try below code works fine at my end:-
<RadioGroup
android:id="#+id/add_reminder_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:gravity="center_horizontal"
android:orientation="vertical" >
<RadioButton
android:id="#+id/add_reminder_daily"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Daily" />
<RadioButton
android:id="#+id/add_reminder_weekly"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Monthly" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >
<RadioButton
android:id="#+id/add_reminder_monthly"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Weekly" />
<RadioButton
android:id="#+id/add_reminder_yearly"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Yearly" />
</LinearLayout>
</RadioGroup>
use this code :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<RadioGroup
android:id="#+id/add_reminder_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="#dimen/zero"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >
<RadioButton
android:id="#+id/add_reminder_daily"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="daily" />
<RadioButton
android:id="#+id/add_reminder_weekly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="weekly" />
</LinearLayout>
<LinearLayout
android:layout_width="#dimen/zero"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >
<RadioButton
android:id="#+id/add_reminder_monthly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="monthly" />
<RadioButton
android:id="#+id/add_reminder_yearly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="yearly" />
</LinearLayout>
</RadioGroup>
</LinearLayout>

Swipe between two layouts overlapped on each other in Framelayout

I want to swipe between two linear layouts which are wrapped in frame layout. At one time, only one of the linear layout is visible. I am using button to show/hide them. I want to implement swipe functionality in them. I tried ViewFliper but didn't work out on finger swipe. Is it possible to do it using ViewPager?
Layout XML is
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00000000" >
<LinearLayout
android:id="#+id/layTopUp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/yellowspace"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical"
android:padding="25dp"
android:visibility="visible" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="XXX"
android:textColor="#000000" />
<Spinner
android:id="#+id/spnTopupOperator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp" />
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="XXX"
android:textColor="#000000" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center_vertical|center_horizontal" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="XXX"
android:textColor="#000000" />
<EditText
android:id="#+id/etTopUpCode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="3"
android:hint="Code"
android:inputType="number"
android:maxLength="3" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/etTopUpNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="7"
android:hint="Number"
android:inputType="number"
android:maxLength="7"
android:shadowColor="#000000" />
</LinearLayout>
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="XXX"
android:textColor="#000000" />
<Spinner
android:id="#+id/spnTopupAmount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp" />
<LinearLayout
android:id="#+id/layConv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:gravity="center_vertical|center_horizontal"
android:orientation="horizontal" >
<TextView
android:id="#+id/tvConvertedAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:text="XXX "
android:textColor="#000000" />
<ProgressBar
android:id="#+id/pbConversion"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
</LinearLayout>
<ImageButton
android:id="#+id/bTopUpSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:background="#drawable/sendrechbotton" />
</LinearLayout>
<LinearLayout
android:id="#+id/layScratchCard"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/yellowspace"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical"
android:padding="25dp"
android:visibility="gone" >
<TextView
android:id="#+id/textView6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="XXXX"
android:textColor="#000000" />
<Spinner
android:id="#+id/spnRechargeOperator"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="XXX"
android:textColor="#000000" />
<EditText
android:id="#+id/etRechargeEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Email"
android:inputType="textEmailAddress" />
<TextView
android:id="#+id/textView8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="XXXX"
android:textColor="#000000" />
<Spinner
android:id="#+id/spnRechargeAmount"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageButton
android:id="#+id/bSendCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/sendcardbotton" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
Solution:
You need to use GestureDetector to get notified whenever swipe occurs on your LinearLayout
Please have a look at GestureDetector for reference.
As of now,I have applied swipe in your code,but I did not have your drawables so I have just used mine.rest of the thing is ready for you.so just use your xml file instead of mine.
Example:
MainActivity.java
package com.mehuljoisar.swipe;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;
public class MainActivity extends Activity {
private GestureDetector gesturedetector = null;
private Intent i;
private FrameLayout flContainer;
private LinearLayout ivLayer1,ivLayer2;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.acti);
flContainer = (FrameLayout) findViewById(R.id.flContainer);
ivLayer1 = (LinearLayout)findViewById(R.id.layTopUp);
ivLayer2 = (LinearLayout)findViewById(R.id.layScratchCard);
gesturedetector = new GestureDetector(new MyGestureListener());
flContainer.setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
gesturedetector.onTouchEvent(event);
return true;
}
});
}
public boolean dispatchTouchEvent(MotionEvent ev) {
super.dispatchTouchEvent(ev);
return gesturedetector.onTouchEvent(ev);
}
class MyGestureListener extends GestureDetector.SimpleOnGestureListener {
private static final int SWIPE_MIN_DISTANCE = 20;
private static final int SWIPE_MAX_OFF_PATH = 100;
private static final int SWIPE_THRESHOLD_VELOCITY = 100;
#Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
float dX = e2.getX() - e1.getX();
float dY = e1.getY() - e2.getY();
if (Math.abs(dY) < SWIPE_MAX_OFF_PATH &&
Math.abs(velocityX) >= SWIPE_THRESHOLD_VELOCITY &&
Math.abs(dX) >= SWIPE_MIN_DISTANCE) {
if (dX > 0) {
Toast.makeText(getApplicationContext(), "Right Swipe",
Toast.LENGTH_SHORT).show();
//Now Set your animation
if(ivLayer2.getVisibility()==View.GONE)
{
Animation fadeInAnimation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.slide_right_in);
ivLayer2.startAnimation(fadeInAnimation);
ivLayer2.setVisibility(View.VISIBLE);
}
} else {
Toast.makeText(getApplicationContext(), "Left Swipe",
Toast.LENGTH_SHORT).show();
if(ivLayer2.getVisibility()==View.VISIBLE)
{
Animation fadeInAnimation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.slide_left_out);
ivLayer2.startAnimation(fadeInAnimation);
ivLayer2.setVisibility(View.GONE);
}
}
return true;
} else if (Math.abs(dX) < SWIPE_MAX_OFF_PATH &&
Math.abs(velocityY) >= SWIPE_THRESHOLD_VELOCITY &&
Math.abs(dY) >= SWIPE_MIN_DISTANCE) {
if (dY > 0) {
Toast.makeText(getApplicationContext(), "Up Swipe",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "Down Swipe",
Toast.LENGTH_SHORT).show();
}
return true;
}
return false;
}
}
}
acti.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/flContainer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:color/black" >
<LinearLayout
android:id="#+id/layTopUp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/darker_gray"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical"
android:padding="25dp"
android:visibility="visible" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="XXX"
android:textColor="#000000" />
<Spinner
android:id="#+id/spnTopupOperator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp" />
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="XXX"
android:textColor="#000000" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center_vertical|center_horizontal" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="XXX"
android:textColor="#000000" />
<EditText
android:id="#+id/etTopUpCode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="3"
android:hint="Code"
android:inputType="number"
android:maxLength="3" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/etTopUpNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="7"
android:hint="Number"
android:inputType="number"
android:maxLength="7"
android:shadowColor="#000000" />
</LinearLayout>
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:text="XXX"
android:textColor="#000000" />
<Spinner
android:id="#+id/spnTopupAmount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp" />
<LinearLayout
android:id="#+id/layConv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:gravity="center_vertical|center_horizontal"
android:orientation="horizontal" >
<TextView
android:id="#+id/tvConvertedAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:text="XXX "
android:textColor="#000000" />
<ProgressBar
android:id="#+id/pbConversion"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
</LinearLayout>
<ImageButton
android:id="#+id/bTopUpSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:background="#drawable/icon" />
</LinearLayout>
<LinearLayout
android:id="#+id/layScratchCard"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/icon"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical"
android:padding="25dp"
android:visibility="gone" >
<TextView
android:id="#+id/textView6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="XXXX"
android:textColor="#000000" />
<Spinner
android:id="#+id/spnRechargeOperator"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="XXX"
android:textColor="#000000" />
<EditText
android:id="#+id/etRechargeEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Email"
android:inputType="textEmailAddress" />
<TextView
android:id="#+id/textView8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="XXXX"
android:textColor="#000000" />
<Spinner
android:id="#+id/spnRechargeAmount"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageButton
android:id="#+id/bSendCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/icon" />
</LinearLayout>
</FrameLayout>
<!-- <TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd" />
-->
</LinearLayout>
slide_left_out.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="-100%p" android:duration="800"/>
</set>
slide_right_in.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="-100%p" android:toXDelta="0" android:duration="800"/>
</set>
I hope it will be helpful !!
Create an Activity extending FragmentActivity.
Create two fragments - each for the linear layouts
Create your View pager adapter extending FragmentStatePagerAdapter.
Supply a list of fragments to yout View pager adapter.

Categories

Resources