I want to create a following kind of layout in android , rite now i have created with fixed height of listview which is causing a problem with different dimension of screens of mobiles.
Initially when this screen appears a button will be at the bottom side only with empty listview and as an when the items will get added in a list view , it grows but button will remain steady at the bottom.
so far i have written following code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="#+id/cText"
android:src="#drawable/c_text"
android:visibility="visible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dip"
/>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false"
/>
<ImageButton
android:id="#+id/cBtn"
android:layout_width="150dip"
android:layout_height="52dip"
android:src="#drawable/preview"
android:layout_alignParentTop="#+id/list"
android:layout_gravity="center_horizontal"/>
</RelativeLayout>
Try this
< ?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"
>
<ImageButton
android:id="#+id/cBtn"
android:layout_centerHorizontal="true"
android:layout_width="150dip"
android:layout_height="52dip"
android:src="#drawable/preview"
android:layout_alignParentBottom="true"
/>
<ListView
android:id="#+id//listview01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/cBtn"
android:layout_marginBottom="10dip"
/>
< /RelativeLayout>
You can add a Button as a footer to List View. The sample code sinppet is shown below
Step1: Create a Button
<Button android:id="#+id/footer" android:gravity="center"
android:layout_gravity="center"
android:text="My Footer"
android:layout_width="wrap_content"
android:layout_height="0dp" android:layout_weight="1"/>
Step2: Make it as Footer to the List View
ListView myList;
View footerView;
ViewGroup footerViewOriginal = (ViewGroup) findViewById(R.id.footer);
footerView = inflater2.inflate(R.layout.footer,footerViewOriginal);
footerView.findViewById(R.id.footer);
myList.addFooterView(footerView, null, true);
Step3: Create on ClickListener and write the action what you want to perform
footerView.findViewById(R.id.footer).setOnTouchListener(new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
return false;
}
Related
Good day.
I have an android application. In my application, I have a custom listView with 5 columns that are textViews. The user can click the rows, once he does, the row layout will change, changing the last 2 textViews to EditTexts. I then register the new EditTexts onto my custom keyboard taken from this example - kindly note that I did a functional copy-paste of his example with regards to the custom keyboard class and how to make it work in the main layout. However, when I click the EditText in the row, my custom keyboard does not show up at all.
I have a global variable as such:
CustomKeyboard mCustomKeyboard;
And in my onCreate() method in the activity, I do:
mCustomKeyboard= new CustomKeyboard(this, R.id.keyboardview, R.xml.custom_keyboard);
This is my layout, I have the KeyboardView at the bottom of the Layout:
<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"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".SearchResult" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- A lot of views go here, enclosed in my linear layout -->
</LinearLayout>
<android.inputmethodservice.KeyboardView
android:id="#+id/keyboardview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:visibility="gone" />
</RelativeLayout>
Here is the code that changes the layout. What I do is that I take the row values from the old layout, get the new layout search_result_inflate, then set the texts of the new layout using the values I got. Kindly note the mCustomKeyboard.registerEditText(R.id.qtyInputSearchResult); line after inflating the layout:
private void changeLayout(final View view){
//get views from old layout
TextView textViewQuantity = (TextView)view.findViewById(R.id.qtyInput);
TextView textViewDiscountReq = (TextView)view.findViewById(R.id.discInput);
TextView textViewName = (TextView)view.findViewById(R.id.dialogItemName);
TextView textViewPrice = (TextView)view.findViewById(R.id.price);
TextView textViewDiscount = (TextView)view.findViewById(R.id.discount);
//store values in strings
String itemName = textViewName.getText().toString();
String itemPrice = textViewPrice.getText().toString();
String itemDiscount = textViewDiscount.getText().toString();
String itemQty = textViewQuantity.getText().toString();
String itemDisc = textViewDiscountReq.getText().toString();
//set the view to gone
textViewQuantity.setVisibility(View.GONE);
textViewDiscountReq.setVisibility(View.GONE);
textViewName.setVisibility(View.GONE);
textViewPrice.setVisibility(View.GONE);
textViewDiscount.setVisibility(View.GONE);
//get the old layout
LinearLayout ll_inflate = (LinearLayout)view.findViewById(R.id.search_result_layout);
//get the inflate/new view
View child = getLayoutInflater().inflate(R.layout.search_result_inflate, null);
//get the views in the new view, populate them
TextView newName = (TextView)child.findViewById(R.id.dialogItemName);
newName.setText(itemName);
TextView newDiscount = (TextView)child.findViewById(R.id.discount);
newDiscount.setText(itemDiscount);
TextView newPrice = (TextView)child.findViewById(R.id.price);
newPrice.setText(itemPrice);
EditText qtyInput = (EditText)child.findViewById(R.id.qtyInputSearchResult);
qtyInput.setText(itemQty);
EditText discInput = (EditText)child.findViewById(R.id.discInputSearchResult);
discInput.setText(itemDisc);
//show new layout
ll_inflate.removeAllViews();
ll_inflate.removeAllViewsInLayout();
ll_inflate.addView(child);
mCustomKeyboard.registerEditText(R.id.qtyInputSearchResult);
}
Here is my search_result_inflate.xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/search_result_inflate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:minHeight="50dp"
android:orientation="horizontal"
android:padding="1dip"
android:weightSum="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="horizontal"
android:padding="1dip" >
<TextView
android:id="#+id/dialogItemName"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="2dp"
android:layout_weight="0.54"
android:gravity="center"
android:text="Item Name"
android:textSize="23sp" />
<TextView
android:id="#+id/price"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="2dp"
android:layout_weight="0.14"
android:gravity="center"
android:text="Price"
android:textSize="23sp" />
<TextView
android:id="#+id/discount"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="2dp"
android:layout_weight="0.10"
android:gravity="center"
android:text="Discount"
android:textSize="23sp" />
<EditText
android:id="#+id/qtyInputSearchResult"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="2dp"
android:layout_weight="0.14"
android:background="#layout/edittext_selector"
android:gravity="center"
android:hint="qtyInput"
android:textColorHighlight="#color/white_opaque"
android:textSize="23sp" >
</EditText>
<EditText
android:id="#+id/discInputSearchResult"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.11"
android:background="#layout/edittext_selector"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center"
android:hint="discInput"
android:textColorHighlight="#color/white_opaque"
android:textSize="23sp" />
</LinearLayout>
</LinearLayout>
As you can see, I have 2 editTexts and I registered qtyInputSearchResult to the custom keyboard class. However, the custom keyboard does not show up.
I also tried to use the custom keyboard class on an editText in another activity and it works just fine. Am I missing something here? I'm confused as to why the custom keyboard does not show up properly.
Any help is very much appreciated, thank you.
Got it, I placed the keyboard layout in the search_result_inflate.xml like so:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/search_result_inflate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:minHeight="50dp"
android:orientation="horizontal"
android:padding="1dip"
android:weightSum="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="horizontal"
android:padding="1dip" >
<!-- a lot of components here -->
</LinearLayout>
<android.inputmethodservice.KeyboardView
android:id="#+id/keyboardview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:visibility="gone" />
</RelativeLayout>
I'm trying to create a custom view in android that I can use in the same way as a LinearLayout. The custom view should add two TextView on top of whatever I add inside the layout. How can I control the visibility of the contents of my custom view? I have to be able to add contents at design time and at run time visibility of that nested contents should be toggled, but not those two TextViews.
My question is somewhat similar to this one which didn't really get a satisfactory answer.
I've created a custom view that extends LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"
>
<TextView
android:id="#+id/txt_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="My title"
android:layout_marginLeft="10dp"
/>
<TextView
android:id="#+id/txt_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginRight="10dp"
android:text="My button"
android:onClick="txtButton_onClick"
android:clickable="true"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/all_contents"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
android:layout_marginTop="10dp"
/>
<!-- This is where I _want_ to add all nested contents to make it easy to toggle its visibility -->
</merge>
All nested content I want to be contained in the LinearLayout at the bottom, so that when I click txt_button I can set visibility on all_contents to gone and make that disappear. I still want txt_title and txt_button to continue being visible, so I can toggle showing the content or not.
The custom view is supposed to be called like this:
<org.my.app.view.SlidingLayoutView
android:id="#+id/slv_date_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
custom:titleString="Date and time"
custom:buttonString="Change">
<!-- This is where all nested contents should go -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Example nested content"
/>
</org.my.app.view.SlidingLayoutView>
What I don't get is how to decide that nested contents goes into the all_content LinearLayout. Or am I thinking about this all wrong? Does nested content end up at the very bottom of the custom view, and if so how do I toggle its visibility and not my two TextView?
By on top of do you mean above in the linear layout? I think that your xml should work if you take out the all_contents LinearLayout, things will be added to the LinearLayout. Make your xml like this.
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal"
>
<TextView
android:id="#+id/txt_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="My title"
android:layout_marginLeft="10dp"
/>
<TextView
android:id="#+id/txt_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginRight="10dp"
android:text="My button"
android:onClick="txtButton_onClick"
android:clickable="true"
/>
</LinearLayout>
<!-- This is where I _want_ to add all nested contents to make it easy to toggle its visibility -->
</merge>
I would add two methods in the class like this which you can use to toggle the visibility of your contents or the textViews at the top:
public void setTopTextViewVisibility(int visibility){
for(int i = 0; i < getChildCount(); i ++){
View view = getChildAt(i);
if(view.getId() == R.id.txt_title || view.getId() == R.id.txt_button){
view.setVisibility(visibility);
}
}
}
public void setContentVisibility(int visibility){
for(int i = 0; i < getChildCount(); i ++){
View view = getChildAt(i);
if(!(view.getId() == R.id.txt_title || view.getId() == R.id.txt_button)){
view.setVisibility(visibility);
}
}
}
I would use a FrameLayout, you can put a linear layout inside the frame and then put all your views inside that and make a new frame for each group of views.
Here's the basic structure of a menu screen I did where once you click a button it shows a new frame with more options.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/mayne" >
<FrameLayout
android:id="#+id/frameMain" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView1" />
<Button
android:id="#+id/button1" />
<Button
android:id="#+id/button2" />
</RelativeLayout>
</FrameLayout>
<FrameLayout
android:id="#+id/frameDiff" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/btnMed" />
<Button
android:id="#+id/btnHard" />
<Button
android:id="#+id/btnEasy" />
<TextView
android:id="#+id/textView2" />
<Button
android:id="#+id/btnCancel" />
</RelativeLayout>
</FrameLayout>
I am having a little trouble with this relative layout:
<?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"
android:background="#drawable/background" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="#string/one_string"
android:onClick="goToScene2" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="#string/two_string"
android:onClick="goToScene1" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/three_string" />
<ImageView
android:id="#+id/custView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:url="#drawable/panel_sets" />
</RelativeLayout>
wich renders the activity like this (scene2 in transition):
But i want to move ImageView like this image in order to later move it by aplying a transition in other layout.xml (this will be scene1). How can i do it?
Thank you very much
You Can Use Custom SlidingDrawer and canvas object to draw whatever you want
1.Create Custom class by implementing View and try this:
Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL);paint.setColor(Color.BLACK); canvas.drawPaint(paint);paint.setColor(Color.WHITE); canvas.drawCircle(100,100,30,paint);
In XML Layout try to set yout custom class and slidingdrawer
<SlidingDrawer
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/Mydrawer" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:handle="#+id/handle"
android:content="#+id/content"><com.exmaple.MyCustomView
android:id="#+id/customview" android:layout_width="fill_parent"
android:layout_height="fill_parent"></com.exmaple.MyCustomView><ImageView
android:id="#id/handle" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="#drawable/def_tray" /></SlidingDrawer>
And finally in you Activity defined what happen when drawer close and open
MyslidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener() { #Overridepublic void onDrawerClosed(){}});MyCustomView customView = (MyCustomView) findViewById(R.id.mycontent);customView.setOnTouchListener(new OnTouchListener() {#Override
public boolean onTouch(View v, MotionEvent event) {return true;}});
I have a scrollview in my android app that supports overscroll and has a nice bounce effect. What I would like to do is add a view that is initially hidden to the user, but if they scroll up beyond the initial view, then they can see it. How can I do this? Is it possible to do this using just xml?
You can place the initial view and the additional view in a LinearLayout, and when the scroll view is created, you can immediately scroll downwards to the initial view. You can set the initial scroll offset using the xml attribute android:scrollY.
By code you can definitely achieve this. In this sample code I have 15 buttons in srollview. And hide 1st button for initial display.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ScrollView hscrollViewMain = (ScrollView)findViewById(R.id.sview);
hscrollViewMain.post(new Runnable() {
public void run() {
Button bt2 = (Button)findViewById(R.id.button2);
int nY_Pos = bt2.getTop();
// scroll to top of bt2
hscrollViewMain.scrollTo(0,nY_Pos);
}
});
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/sview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:id="#+id/bt1"
android:layout_height="wrap_content"
android:text="Button 1" />
<Button
android:id="#+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 2" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 3" />
.
.
.
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button 15" />
</LinearLayout>
</ScrollView>
I have following main layout:
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
<ViewFlipper android:id="#+id/viewstack"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Here I want to add my views which are located in separated xml files. -->
</ViewFlipper>
</LinearLayout>
Here is example of my view:
view_url.xml
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:gravity="center">
<EditText android:text="#+id/EditText01"
android:id="#+id/EditText01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btnGenerate"
android:text="Generate"/>
</LinearLayout>
view_text.xml
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
<EditText android:text="#+id/EditText01"
android:id="#+id/EditText01"
android:layout_height="wrap_content"
android:contentDescription="Enter your text here"
android:layout_width="fill_parent"
android:height="200dp"/>
</LinearLayout>
I am trying to add views:
viewstack = (ViewFlipper) findViewById(R.id.viewstack);));
View viewText = (View) findViewById(R.layout.view_text);
viewstack.addView(viewText); < -- Emulator is crashing at this line
View viewUrl = (View) findViewById(R.layout.view_url);
viewstack.addView(viewUrl);
I dont have any idea what is wrong with my code. I decided to put all my views in one file, but I still want to know how to fix my initial code.
Yout View viewUrl = (View) findViewById(R.layout.view_url); is very wrong. findViewById is kinda like the get(String key) method the the directory where your directory is your current view/activity. It only looks up the element with that Id under it's children.
To create Java objects out of XML files you need use you need to use the LayoutInflater. Which is pretty straight forward, out of that you get the object you can pass to viewstack.addView(..) method.
Another way to achieve this would be to just include the other XML files into the first one by using either the include, merge tags, or the ViewStub. Depending on your requirements these might not be an option though, but what you are describing they should be, and you should use these instead of doing it programatically because it's just cleaner this way.
maybe this help:
this.flipper=(ViewFlipper)findViewById(R.id.flipper);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.viewLoader=(View)inflater.inflate(R.layout.search_result_grid, null);
flipper.addView(viewLoader);
this.viewResultGrid=(View)inflater.inflate(R.layout.search_result_grid, null);
gvSearchResult=(GridView)viewResultGrid.findViewById(R.id.gridViewSearchResult);
flipper.addView(viewResultGrid);
It's name suggests that It will find by id not by layout.You should understand difference between layout and id.use like this one View v=(View)findViewById(R.id.your_view_id);
Easiest way to add by inflating View. Here some small snippet where you can find reference.
private View viewText;
private TextView txtPost;
private void setViewFlipperPost(String postData, String postType) {
if (postType.toLowerCase().toString().equals("text")) {
viewText = LayoutInflater.from(mContext).inflate(R.layout.activity_full_screen_textpost, null, false);
viewText.setTag(TAG_TEXT);
txtPost = (TextView) viewText.findViewById(R.id.txtTextPostFullScreenText);
txtPost.setText(postData);
viewFlipper.addView(viewText);
}
}
use viewflipper
<?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:background="#drawable/white"
android:orientation="vertical" >
<ViewFlipper
android:id="#+id/view_flipper"
android:layout_width="match_parent"
android:layout_height="410dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="first layout"
android:textColor="#845965"
android:textSize="25dp"
android:textStyle="bold" >
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:text="second layout"
android:textColor="#654123"
android:textSize="25dp"
android:textStyle="bold" >
</TextView>
</LinearLayout>
//you can add many layout here
</viewFlipper>
<Button
android:id="#+id/flipbyclickNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/bn1"
android:onClick="flipByClickNext" />
<Button
android:id="#+id/flipbyclickprevious"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="flipByClickPrevious"
android:background="#drawable/bp1" />
</LinearLayout>
MainActivity.java
public class MainActivity extends Activity {
private ViewFlipper viewFlipper;
//Button next,prev;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewFlipper = (ViewFlipper) findViewById(R.id.view_flipper);
}
public void flipByClickNext(View v)
{
if(viewFlipper.isFlipping())//Checking flipper is flipping or not.
{
viewFlipper.stopFlipping(); //stops the flipping .
}
viewFlipper.showNext();//shows the next view element of ViewFlipper
}
public void flipByClickPrevious(View v)
{
if(viewFlipper.isFlipping())//Checking flipper is flipping or not.
{
viewFlipper.stopFlipping(); //stops the flipping .
}
viewFlipper.showPrevious();
}
}