Skip to content

Instantly share code, notes, and snippets.

@edBaev
Created March 13, 2014 10:46
Show Gist options
  • Save edBaev/9526067 to your computer and use it in GitHub Desktop.
Save edBaev/9526067 to your computer and use it in GitHub Desktop.
Было
package com.buyfolio.control;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import com.buyfolio.R;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Dmitriy Dovbnya on 07.03.14.
*/
public class LinearRadioGroup extends RadioGroup {
private Context context;
private LayoutInflater inflater;
private List<String> values;
private String rightValue;
public LinearRadioGroup(Context context) {
super(context);
this.context = context;
}
public LinearRadioGroup(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
}
public void setTextValues(List<String> values) {
ArrayList<String> radioButtonValues = (ArrayList<String>) values;
String rightValue = radioButtonValues.get(radioButtonValues.size() - 1);
this.rightValue = rightValue;
if (radioButtonValues.remove(rightValue)) {
this.values = radioButtonValues;
}
this.inflater = LayoutInflater.from(this.context);
initViews();
}
private void initViews() {
addView(createLeftView(this.context.getString(R.string.radio_buttons_any)));
for (String value : values) {
addView(createView(value));
}
addView(createRightView(rightValue));
}
private View createLeftView(String value) {
RadioButton radioButton = (RadioButton) inflater.inflate(R.layout.linear_radiobutton_left, this, false);
radioButton.setId(value.hashCode());
radioButton.setTag(value);
radioButton.setText(value);
radioButton.setChecked(true);
return radioButton;
}
private View createView(String value) {
RadioButton radioButton = (RadioButton) inflater.inflate(R.layout.linear_radiobutton_item, this, false);
radioButton.setId(value.hashCode());
radioButton.setTag(value);
radioButton.setText(value + "+");
return radioButton;
}
private View createRightView(String value) {
RadioButton radioButton = (RadioButton) inflater.inflate(R.layout.linear_radiobutton_right, this, false);
radioButton.setId(value.hashCode());
radioButton.setTag(value);
radioButton.setText(value + "+");
return radioButton;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment