I am currently writing a custom ImageView. what im actually turning this imageview into is a multiple state button.
In my case, the button has three states, answered with yes, answered with no and unanswered.
I strictly don’t want to use a radiogroup/button.
I have the basic setup for the imageview. It has onclick functionality to properly change the image depending on the state. Which for now is just a checkbox with a cross, an empty checkbox and a checkbox with a tick.
What I want is, when the state changes(the image is clicked) i want text, which should Always be around, and never ontop of the imageview. To change its value aswell. I want to be able to call a method similar to customCompInstance.getText(); customCompInstance.getText();
What im thinking is, the custom imageview class should have a TextView member, but I have NO clue whatsoever how to place it on the left, horizontally aligned to the imageview.
It is NOT an option to just use two different elements in xml.
Is adding a textview and placing it to the right of the imageview the right solution, if not, what do you suggest, if so, please give me some tips on how to actually achieve this.
Simplified version of my class:
public class AnswerImageView extends ImageView {
private AnswerState mSelectionState;
/**
* @param context
*/
public AnswerImageView(Context context)
{
super(context);
// TODO Auto-generated constructor stub
setImageResource(R.drawable.answer_none);
setTag(R.drawable.answer_none);
mSelectionState = AnswerState.ANSWER_NONE;
}
/**
* @param context
* @param attrs
*/
public AnswerImageView(Context context, AttributeSet attrs)
{
super(context, attrs);
// TODO Auto-generated constructor stub
setImageResource(R.drawable.answer_none);
setTag(R.drawable.answer_none);
mSelectionState = AnswerState.ANSWER_NONE;
}
/**
* @param context
* @param attrs
* @param defStyle
*/
public AnswerImageView(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
setImageResource(R.drawable.answer_none);
setTag(R.drawable.answer_none);
mSelectionState = AnswerState.ANSWER_NONE;
}
public AnswerState getSelectionState() {
return mSelectionState;
}
public void setSelectionState(AnswerState selectionState) {
this.mSelectionState = selectionState;
}
}
I have a method that reacts to onclicks, that all works fine. im purely asking about adding a textview in this component. Essentially combinding two components into one.
You should extend from
TextViewinstead ofImageViewand have a look at methodsTextView.setCompoundDrawableXXX. Here is the link for the doc.