How can i add a customized footer layout in a activity layout - android

Hello Community i am new and need your expert opinions.
i have custom footer.xml layout with some buttons on it , i want to add this xml to my activity layout, and i also want to implement click listner for button. Need your guidance.enter image description here
i am able to include footer through
<include layout="#layout/footer" />
it includes the footer layout in activity layout, but there are some buttons i also want to implement action for them.is there any way ?

You can use this on your button definition (inside the footer layout)
android:onclick="clickMethodName"
Just ensure that any class that uses that layout implements 'clickMethodName'.
Alternatively, you can set the onClickListener in your class, after finding the button by id.
See the official documentation for more details and examples, right at the top:
http://developer.android.com/reference/android/widget/Button.html

Related

Include template layout and add components on it

I defined a layout and want to use it as template for my other activitys (same background color, distance to margin etc.). So i`m trying to include it by
<include layout="#layout/template">
That does work. But i want to place buttons on the included layout like this
<include layout="#layout/template"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:id="#+id/applyLeave"
android:layout_alignTop="#+id/upperEdge"
style="#style/buttons"/>
</include>
(e.g. #+id/upperEdge is part of the included layout and i want to set the button below the included component)
Is it possible and how do i do this?
I think it's not possible to add Views by XML on include layout.
You can add views, like buttons, after TAG. Also, if you want to add views dynamically, you can use Java code and add views here.
Here a sample code:
//Get your object layout by ID
LinearLayout myLayout = (LinearLayout)findViewById(R.id.your_include_layout);
//Create a new button
Button mButton = new Button();
mButton.setText("This is a dynamic button");
//Add button to the layout
myLayout.addView(mButton);
I hope this help you.

How to overlay a small view on a Main view without fully covering main view?

So I need the view of my settings to display over my main page.where there is a "setting"button in Main page which opens this settings view. But I want My main page to be visible beneath my settings view which only covers a half or less of the main view.
I tried adding
<org.example.myCustomView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:theme="#android:style/Theme.Dialog" />
Which I found from stackoverflaw itself. But I cannot do it instead the application corrupts at button click.
I am not sure I got this too correct, Or is there any other clear way to do it?
I replaced myCustomView with my relevent class and created the manifest also but it did not work.
If there is any other alternative way to do this mention to me.
I am not talking about how to place a TextView, Button, EditText on a view
I am talking about completely two layouts.
Below image is only an example to express my question.
I think you need to utilize layoutinflater. Here is a simple example how to use it
setContentView(R.layout.yourMainView);
LayoutInflater mInflater = LayoutInflater.from(getApplicationContext());
View overView = mInflater.inflate(R.layout.yourSmallView, null);
addContentView(overView, new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
Use FrameLayout.FrameLayout is like container.In it place first your bluelayout and then your settings layout.It will show as if settings layout is placed on top of your blue layout.
and then hide and show your settings layout on the onclick when required.
eg:
You could use a Dialog Fragment which would be much more simpler and show more complicated stuff on UI with better responsiveness. Have a look at Dialog fragment:
http://developer.android.com/reference/android/app/DialogFragment.html

Android GraphicsView enbbeded in layout

How to enbbed a GraphicsView into a layout? Or how do I add buttons and textViews to a GraphicsView? Could some one post a simple working example?
-Henry
I don't think you can add other Views inside a View component.
GraphicsView is not a default Android SDK class, so we can't know what you have there, sorry.
Make a Layout component to be able to add View components inside it.
To embed your GraphicsView in a layout in xml use something like:
<com.package.GraphicsView
id="#+id/graphics"
...
/>

Displaying popup images on button click

Please refer the image given in the url
http://docs.google.com/Doc?docid=0AQhgDtGvE2HgZGZ6cmtua185M2RneG5nYmNm&hl=en
My query is, How can I display the messages corresponding to the rounded buttons and the table row , when I click on the rounded button with question mark.
I know, I have to use listener for the ? button , but what should I do in listener exactly, such that when I click, it shows those alerts(images) and when I click again, it disappears.
For this UI, I have used Relative layout as was suggested here -- Aligning components at desired positions -- and it worked perfect for me.
So, do I need to change my base layout altogether for accomplishing this?
You can use a FrameLayout as the base for your ui layout and then add an ImageView overlay. For example:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/MainFrame"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Put your normal layout stuff here -->
</FrameLayout>
Then in your code you can create the ImageView and add it to the MainFrame and it will overlay your UI, like this:
FrameLayout mainFrame = (FrameLayout)findViewById(R.id.MainFrame);
ImageView overlay = new ImageView(this);
overlay.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.overlay));
mainFrame.addView(overlay);
Then later you can call:
mainFrame.removeView(overlay);
to have it go away.

Android: How to Create a Custom button widget

I would like to create a button with circular or rectangular background, text and an image below or above the text.
Here is the CustomButton Layout where I added the objects (background and text - ImageView is missing):
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:orientation="horizontal" android:layout_width="wrap_content" android:layout_gravity="center_vertical|center_horizontal">
I would like to create a CustomButton object with methods setText() and setImage() which would change the button text and image and place multiple CustomButtons into main layout.
Does anyone know how to create a custom layout, place it into another layout(main) and modify its elements from the activity which is bound to main layout?
I would really appreciate your help.
Thanks!
Hey, To create a circular button or rectangular button you can use shape.
It can be done in .xml file.
see this Click Here
If you want programmatic access, you should subclass View and do your work there in java. You can still do the layout in xml, but have the image and text methods that you want. You will then be able to use this in another layout to place your CustomButtons.

Categories

Resources