RadioButton with more than text - android

I'm trying to create a RadioGroup with RadioButtons that have more than text only.
The image below will make things easier to understand.
I want the RadioButton to be selected when the user clicks somewhere in the layout around it.
I've tried do do somthing lik this:
<RadioGroup>
<RelativeLayout>
<RadioButton>
<...other stuff>
</RelativeLayout>
</RadioGroup>
But that didn't work.
Does somebody know how to easily get the requested layout and behaviour? Thanks
EDIT:
I forgot to mention that I don't want to use a list. I want all items to be visible because there are maximum three. Also, the container is a ScrollView

As Der Golem said you can use ListView and set it to be in a single choice mode: list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
But if you need only few layouts you can register Click listener to your layouts and call onClick events on RadioButtons:
bigLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
radioButton.performClick();
}
});
Hope it will help

Related

Why when I use setClickable(true) it's not show the action of click

Actually, I use a ListView and when I use setClickable(false) I have the animation as if I clicked on a button you see? The animation that shows you click. Which is not normal, I think, basic.
And when I use setClickable(true) I no longer have the animation, as well as if I use
convertView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
And i would like to use the OnClickListener but I think it would be better for the user to see that he can click, so to have the animation when you click.
So, I'd like to see when the user clicks on an item in the list, it does the action I want (I'll add that later) but let's imagine a Toast but it displays the effect as if you click on a button. The effect i got if i use setClickable(false) (the default setting).
That's the ripple effect !
In the row's layout of the ListView just add:
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
This will add the Ripple effect. If you want to show it on top of the other views, use the forground attribute:
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
add this foreground:?attr/selectableItemBackground to your view attribute, it should work

Change background of all buttons

I would like to change the background of all the Buttons in a View.
android:background="#drawable/button_red"
And i would like to do this in an OnClick() event.
android:onClick="ChangeCouleur"
I would like to do this in a foreach loop, but i am not sure how to do this.
For example:
for( b in ... )
if (b.getid()!=idofthebutton)
b.setbackgroud(button_red)
Thanks for any help!
Put all your Buttons in an Array of Buttons, then cycle to it an change the background.
Button button1 = (Button)this.findViewById(...);
Button button2 = (Button)this.findViewById(...);
Button button3 = (Button)this.findViewById(...);
Button[] buttons={button1, button2, button3};
for (Button currentButton : buttons) {
currentButton.setBackgroundResource(R.drawable.my_new_background);
}
One thing you could do is subclass Button, then make all the buttons in you app instances of your new class. That way, if you decide that you want to adjust the color or change something else, you only have to do it once, and it will change all the buttons in your app. Here's a question that should give you some pointers on how to do that.
For changing the background of the clicked button
public void changeColor(View v) {
v.setBackground(btn_red);
}
You will have to get a reference to all the Buttons. Add them to an ArrayList or something similar. In your ChangeCouleur method use a loop to iterate through all the buttons changing the color of each one.
Create .XML file in your “res/drawable/” and use selector attribute in it.And use different images for the button.Please refer this link.
http://www.mkyong.com/android/android-imagebutton-selector-example/
This will clear your idea. :)

Making custom android views "tappable" with a feedback highlight

I'm using a custom view expanded from a XML layout in a horizontal scroll view as a sort of horizontal image list but I'm not sure how to get them to appear clickable/tappable (ie they highlight when tapped) or how to capture these events. I think I've tried setOnClickHandler without it working. I'm also trying to get a simple TextView to do the same. I've also tried setting android:clickable="true" but that hasn't helped either. Any ideas?
To take care of the visual feedback use an xml Selector, and set it as the View's background.
To handle click events use
mView.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//your code here
}
});

how to zoom-in interface? Android development

In my Android application, I have an activity with three layouts: A left layout, a middle layout, and a right layout.
The right layout is the main one. I want the right layout to zoom into fullscreen when I click a button. If you have the specific code,it's better.
Thanks very much!
If I got your question right:
Your button's OnClickListener should look like something like this:
OnClickListener listener = OnClickListener() {
public void onClick(View v){
findViewById(R.id.left_layout).setVisibility(View.INVISIBLE);
findViewById(R.id.center_layout).setVisibility(View.INVISIBLE);
};
This by itself will not get your right layout to fullscreen. You'll need to add something the below to your right layout for it to "auto fullscreen":
android:layout_width = "0dp";
android:layout_weight = "1";
if you don't do that, you'll have to resize the right layout from the "listener" above.
Hmm, the question is vague, but if I understand correctly, what you want to do is hide the left and center layouts when a button is clicked, so that the right layout becomes full-screen?
Without more details, it's not easy to give you a more precise answer (please post your current layout), but I would do something like:
// this code in your Activity:
// this method is bound to button onCLick (android:onClick="clickButton")
public void clickButton(View view) {
findViewById(R.id.left_layout).setVisibility(View.INVISIBLE);
findViewById(R.id.center_layout).setVisibility(View.INVISIBLE);
}
And to revert back to a 3-layout display, you do the opposite (View.VISIBLE)

Can I deactivate buttons/edittexts from my layout? (visible but deactivated)

I have a layout with a spinner and a lot of textboxes and buttons.
I need to make appear some elements of the layout when one of the options of the spinner is selected and to make disappear when other is selected. ----> PROBLEM SOLVED!!!
But also, I need to deactivate some elements of the layout. I mean that they have to be visible, but the user can't press buttons or edit edittext's
Yes, you can.
Assuming you have a handle to your layout you can do smth like this:
yourLayoutToShow.setVisibility(View.VISIBLE)
or
yourLayoutToHide.setVisibility(View.GONE)
UPDATE:
To get a handle to your layout (the one you want to show/hide dynamically) you need to do smth like this:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_activity);
LinearLayout viewToShowOrHide =
(LinearLayout) findViewById(R.id.view_to_show_or_hide);
}
You can disable a control by doing ...
myControl.setEnabled(false);

Categories

Resources