I am attempting to change the background of a tab of my application by selecting a Radio Button from a RadioGroup, however I am not sure how to go about this.
So far I have
Favs.java:
import android.app.Activity;
import android.os.Bundle;
public class Favs extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.favs);
}
}
which points to this .xml file -> favs.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="What is your favorite color?"
android:padding="3dip"/>
<RadioGroup android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton android:id="#+id/radio_red"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Red"
android:onClick="onClick" />
<RadioButton android:id="#+id/radio_yellow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yellow" />
</RadioGroup>
</LinearLayout>
I understand that the android:onClick="onClick" needs to be there however I have no idea what to do after this.
hi use below code for changing the background according to radio button selection
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="fill_parent"
android:orientation="vertical"
android:id="#+id/LinearLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="What is your favorite color?"
android:padding="3dip"/>
<RadioGroup android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/Group1"
android:orientation="vertical">
<RadioButton android:id="#+id/radio_red"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Red"
/>
<RadioButton android:id="#+id/radio_yellow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yellow" />
</RadioGroup>
</LinearLayout>
Activity
public class Change extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final LinearLayout ll=(LinearLayout) findViewById(R.id.LinearLayout);
final RadioButton radio_red = (RadioButton) findViewById(R.id.radio_red);
final RadioButton radio_yellow = (RadioButton) findViewById(R.id.radio_yellow);
radio_red.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
ll.setBackgroundColor(Color.RED);
}
});
radio_yellow.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
ll.setBackgroundColor(Color.YELLOW);
}
});
}
}
Related
I have the following layout.xml containing one ScrollView with some elements(picture and text)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/clickable"
android:orientation="vertical">
<LinearLayout
android:id="#+id/layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight="1"
android:layout_gravity="center"
android:src="#drawable/crown" />
<TextView
android:id="#+id/n1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:text="some text" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight="1"
android:layout_gravity="center"
android:src="#drawable/medal" />
<TextView
android:id="#+id/n2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:text="some text" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_weight="1"
android:layout_gravity="center"
android:src="#drawable/star" />
<TextView
android:id="#+id/n3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:text="some text" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
MainActivity.java
public class MainActivity extends Activity{
LayoutInflater inflater;
RelativeLayout MyLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
inflater = LayoutInflater.from(this);
MyLayout = (RelativeLayout) inflater.inflate(R.id.layout, null, false);
MyLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Log.d("TAG"," I'm clicked! ");
}
});
Click Listener above does not work when I click screen!!!
But if I change code to this - everything is working
MyLayout.findViewById(R.id.clickable).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Log.d("TAG"," I'm clicked! ");
}
});
So why should I set click listener to LinearLayout inside ScrollView inside parent RelativeLayout?
Why click listener does not work for root xml element RelativeLayout???
The problem is that your ScrollView is intercepting the touch events and not propagating them to parent layouts (in this case your RelativeLayout).
This thread might have some useful information about this topic.
Just add android:clickable="false" in your ScrollView. Then change your MainActivity like below:
public class MainActivity extends Activity {
LinearLayout myLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myLayout = (LinearLayout) findViewById(R.id.layout);
myLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Log.d("TAG"," I'm clicked! ");
}
});
}
}
Note: activity_main.xml is xml file which you are loading.
Now your OnClick will work as expected.
I have a Relative layout as:
<RelativeLayout
android:id="#+id/iPay_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="· Use iPay"
android:textColor="#686A86"
android:textSize="18sp" />
<Button
android:layout_width="50dp"
android:layout_height="35dp"
android:layout_alignParentRight="true"
android:background="#drawable/i_pay"
android:textAllCaps="false"
android:textColor="#ffffff" />
</RelativeLayout>
I want my relative layout to perform onCLickListener but does not work.
I am able to do the setonclicklistener but it works only with the textview part and not for the image.
btniPay.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//for ipay
}
});
This works for the text part only but not for the image. Any idea what I might be missing.
Alternatively, you can add android:clickable="false" in your button xml attribute.
<RelativeLayout
android:id="#+id/iPay_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="· Use iPay"
android:textColor="#686A86"
android:textSize="18sp" />
<Button
android:layout_width="50dp"
android:layout_height="35dp"
android:layout_alignParentRight="true"
android:background="#drawable/i_pay"
android:textAllCaps="false"
android:clickable="false"
android:textColor="#ffffff" />
</RelativeLayout>
may be you can find some good example thats use with imageview and buttons but the easy way i did it by using adding TextView instead of images and buttons.
<RelativeLayout
android:id="#+id/layout1"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:clickable="true"
android:gravity="right">
<TextView
android:id="#+id/englishheading1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/urduheading1"
android:text="English text"
android:textColor="#ffffff"
android:textSize="15sp" />
<TextView
android:id="#+id/urduheading1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:text="urdu text1"
android:textColor="#ffffff"
android:textSize="16sp" />
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_alignParentBottom="true"
android:layout_marginTop="8dp"
android:background="#ffffff" />
</RelativeLayout>
Here is java code to perform onClick.
RelativeLayout layout1 = (RelativeLayout) view.findViewById(R.id.layout1);
layout1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// do something
}
});
see my code easily run change your code:
.xml file
<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="${relativePackage}.${activityClass}" >
<RelativeLayout
android:id="#+id/iPay_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:orientation="horizontal" >
<TextView
android:id="#+id/tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="· Use iPay"
android:textColor="#686A86"
android:textSize="18sp" />
<Button
android:id="#+id/btn"
android:layout_width="50dp"
android:layout_height="35dp"
android:layout_alignParentRight="true"
android:background="#drawable/ic_launcher"
android:textAllCaps="false"
android:textColor="#ffffff" />
</RelativeLayout>
</RelativeLayout>
.java file
public class MainActivity extends Activity {
TextView tv;
Button btn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv=(TextView) findViewById(R.id.tv);
btn = (Button) findViewById(R.id.btn);
tv.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "text", Toast.LENGTH_SHORT).show();
}
});
btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "button", Toast.LENGTH_SHORT).show();
}
});
}
}
Just mark android:clickable="true" in your RelativeLayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_id"
android:clickable="true">
Using ButterKnife lib make bind here:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_xml_name);
ButterKnife.bind(this);
}
#OnClick(R.id.activity_id)
void onActivityClick() {
// do smth ...
}
I'm making a cooking application and I have created a favourite button that seems to work ok i click on it and it changes colour. I tried to create a toast where when I click on the button a message wil come up to say
added to favourites
and
removed from favourites
the code I have used for the toast doesn't have an errors and the application runs perfectly but the toast does not appear
here is my code that I have used
Toast.java
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.Toast;
public class Favourite_Toast extends Activity {
private CheckBox fav;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.recipe);
addListenerOnChk();
}
public void addListenerOnChk() {
fav = (CheckBox) findViewById(R.id.checkBox);
fav.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (((CheckBox) v).isChecked()) {
Toast.makeText(Favourite_Toast.this,
"Added to Favourites", Toast.LENGTH_LONG).show();
}
}
});
}
}
favourite.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"
android:drawable="#drawable/heart_red" />
<item android:state_checked="false"
android:drawable="#drawable/heart_grey" />
</selector>
recipe.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/jbsbackground2"
android:orientation="vertical" >
<ImageView
android:id="#+id/iv_detail"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:scaleType="centerCrop"
android:src="#drawable/barbecuedporkribs" />
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="10dp"
android:layout_below="#+id/iv_detail"
android:background="#3D3C3A" />
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/button1" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_below="#+id/scrollView1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="5dp"
android:text="#string/textView2"
android:layout_toLeftOf="#id/favourites"
android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />
<TextView
android:id="#+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/tvName"
android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="italic"
android:layout_below="#+id/textView2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/checkBox"
android:button="#drawable/favourite"
android:checked="false"
android:layout_alignTop="#+id/textView2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="46dp"
android:layout_marginEnd="46dp"
android:clickable="true" />
<TextView
android:id="#+id/tvTD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/tvTD"
android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold"
android:layout_below="#+id/checkBox"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="#+id/tvIngredients"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvTD"
android:layout_marginTop="2dp"
android:text="#string/tvIngredients"
android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="italic" />
<TextView
android:id="#+id/tvK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvIngredients"
android:layout_marginTop="5dp"
android:text="#string/tvK"
android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />
<TextView
android:id="#+id/tvPreparation"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvK"
android:layout_marginTop="2dp"
android:text="#string/tvPreparation"
android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="italic" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
I've used a checkbox for the favourite button could that be the reason why the toast is not working
Also would anyone be able to tell me how to make the code so that once you have clicked on the favourite button it will stay clicked, because as it is it does not stay clicked on
Thanks in advance
I recommend you change your OnClickListener with OnCheckedChangeListener. It will get invoked when the user checks / unchecks the state of the CheckBox. IMHO, it's the better listener for this widget.
Try the code below
if ((fav.isChecked()) {
Toast.makeText(Favourite_Toast.this, "Added to Favourites", Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(Favourite_Toast.this, "Removed From Favourites", Toast.LENGTH_LONG).show();
}
Use this code in MainActivity... THIS WILL SOLVE YOUR PROBLEM:
public class MainActivity extends Activity {
private CheckBox chk;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
chk = (CheckBox) findViewById(R.id.checkBox1);
chk.setOnClickListener(checkboxClickListener);
}
View.OnClickListener checkboxClickListener = new View.OnClickListener() {
#Override
public void onClick(View view) {
boolean checked = ((CheckBox) view).isChecked();
if (checked) {
Toast.makeText(MainActivity.this,"Added to favourite", Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(MainActivity.this,"Removed from favourite", Toast.LENGTH_LONG).show();
}
}
};
}
I have My Table row like below in my xml layout:
<TableRow
android:layout_marginTop="10dp"
>
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="256dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/titlename"
android:layout_="#+id/playbtn"
android:layout_marginTop="4dp"
/>
<Button
android:id="#+id/playbtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:background="#drawable/play"
android:layout_marginBottom="3dp"/>
<Button
android:id="#+id/pausebtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_toTopOf="#+id/playbtn"
android:layout_alignParentBottom="true"
android:background="#drawable/pause"
android:layout_marginBottom="3dp"/>
</TableRow>
and my output is as below,
my requirement is to show play pause buttons at the same position in my layout?
Could any one help?
Use FrameLayout and put one button over another
Like this
<FrameLayout ... >
<Button
android:id="#+id/playbtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#drawable/play"/>
<Button
android:id="#+id/pausebtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#drawable/pause"/>
</FrameLayout>
This will put Pause button over Play Button. Make the necessary button visible and invisible according to your need
Try using this layout. Use combination of LinearLayout and FrameLayout to achieve the desired result.
<TableRow
android:layout_marginTop="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weight="1"
android:layout_alignLeft="#+id/titlename"
android:layout_="#+id/playbtn"
android:layout_marginTop="4dp"
/>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/playbtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#drawable/play"/>
<Button
android:id="#+id/pausebtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#drawable/pause"/>
</FrameLayout>
</LinearLayout>
</TableRow>
once Try this:
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".8" />
<Button
android:id="#+id/play"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".2"
/>
</TableRow>
Main Activity
private boolean playing = false;
Button play;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
play=(Button) findViewById(R.id.play);
play.setBackgroundResource(R.drawable.pause);
play.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(playing){
playing = false;
play.setBackgroundResource(R.drawable.pause);
}
else {
playing = true;
play.setBackgroundResource(R.drawable.play);
}
}
});
}
Why can't you try merge?
Have a glance of this.
http://android-developers.blogspot.in/2009/03/android-layout-tricks-3-optimize-by.html
You don't need to create two buttons for it. You can do it with single. I have created a sample program. I find this to be a cleaner approach.
Layout for MainActivity
<LinearLayout 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"
android:orientation="vertical"
android:gravity="center">
<Button
android:id="#+id/buttonPlayPause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Here is MainActivity
package in.live.homam.imagebuttonexample;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
private Button buttonPlayPause;
private static final int resourceIdPlay = R.drawable.play;
private static final int resourceIdPause = R.drawable.pause;
private int resourceIdButton = resourceIdPlay;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonPlayPause = (Button) findViewById(R.id.buttonPlayPause);
buttonPlayPause.setBackgroundResource(resourceIdButton);
buttonPlayPause.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(resourceIdButton == resourceIdPlay) {
resourceIdButton = resourceIdPause;
Log.d("Tag", "Playing");
}
else {
resourceIdButton = resourceIdPlay;
Log.d("Tag", "Paused");
}
buttonPlayPause.setBackgroundResource(resourceIdButton);
}
});
}
}
I need a little help.I'm using a ViewFlipper to change views in TabActivity but not really sure how to do it.Here is my code :
MainActivity.class
public class Collections extends Activity implements OnClickListener {
ViewFlipper vFlip;
Button genre, recommended, soon;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.collections_layout);
vFlip = (ViewFlipper) findViewById(R.id.tags_flipper);
genre = (Button) findViewById(R.id.genre_btn);
genre.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
vFlip.getCurrentView();
}
});
recommended = (Button) findViewById(R.id.recom_btn);
recommended.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
vFlip.getCurrentView();
}
});
soon = (Button) findViewById(R.id.soon_btn);
soon.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
vFlip.getCurrentView();
}
});
}
}
I have three different xml, which I want to load with clicking the buttons.Here is the collection_layout.xml
Collection_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF">
<LinearLayout
android:id="#+id/actionbar"
android:layout_width="fill_parent"
android:layout_height="65px"
android:background="#drawable/pink_bar"
android:tileMode="repeat"
android:orientation="vertical">
<ImageView
android:src="#drawable/stampii_logo"
android:id="#+id/stampii_logo_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="20px"/>
</LinearLayout>
<LinearLayout
android:id="#+id/first_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:background="#d229ce">
<Button
android:id="#+id/genre_btn"
android:text="By Genre"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp" />
<Button
android:id="#+id/recom_btn"
android:text="Recommended"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp" />
<Button
android:id="#+id/soon_btn"
android:text="Expect Soon!"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/flip"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF" >
<ViewFlipper
android:id="#+id/tags_flipper"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<include android:id="#+id/genre" layout="#layout/by_genre" />
<include android:id="#+id/recom" layout="#layout/recommended" />
<include android:id="#+id/soon" layout="#layout/expect_soon" />
</ViewFlipper>
</LinearLayout>
</LinearLayout>
So how can i do that?Thanks a lot!
Use ViewFlipper.setDisplayedChild