Reputation: 265
I have this strange problem when I add my custom views to a GridLayout. All the textviews in my Custom view are hidden (or gone, don't know) and when I click my Custom View, they appear.
This is my Custom View:
public class SequenceVOView : LinearLayout
{
TextView lblTitle;
TextView lblTheme;
TextView lblDeadline;
List<ImageView> stars;
ImageView imgSequenceBadge;
ImageView imgRightArrow;
private QuestionSequenceVO _sequence;
public QuestionSequenceVO Sequence {
get {
return this._sequence;
}
set {
_sequence = value;
}
}
public SequenceVOView (Context context) :
base (context)
{
Initialize ();
}
public SequenceVOView () :
base (Application.Context)
{
Initialize ();
}
public SequenceVOView (Context context, IAttributeSet attrs) :
base (context, attrs)
{
Initialize ();
}
public SequenceVOView (Context context, IAttributeSet attrs, int defStyle) :
base (context, attrs, defStyle)
{
Initialize ();
}
void Initialize ()
{
LayoutInflater inflater = (LayoutInflater)Context.GetSystemService (Context.LayoutInflaterService);
View view = inflater.Inflate (Resource.Layout.SequenceVOFragmentLayout, this);
lblTitle = FindViewById<TextView> (Resource.Id.lblSequenceSubject);
lblTheme = FindViewById<TextView> (Resource.Id.lblSequenceTheme);
lblDeadline = FindViewById<TextView> (Resource.Id.lblDeadline);
stars = new List<ImageView> ();
stars.Add(FindViewById<ImageView> (Resource.Id.imgSequenceStar1));
stars.Add(FindViewById<ImageView> (Resource.Id.imgSequenceStar2));
stars.Add(FindViewById<ImageView> (Resource.Id.imgSequenceStar3));
stars.Add(FindViewById<ImageView> (Resource.Id.imgSequenceStar4));
stars.Add(FindViewById<ImageView> (Resource.Id.imgSequenceStar5));
foreach (var item in stars) {
item.SetImageResource (Resource.Drawable.difficultyStar);
item.Visibility = ViewStates.Invisible;
}
imgRightArrow = FindViewById<ImageView>(Resource.Id.imgSequenceRightArrow);
imgSequenceBadge = FindViewById<ImageView>(Resource.Id.imgSequenceBadge);
}
public void setData(QuestionSequenceVO sequence){
_sequence = sequence;
lblTitle.Text = sequence.Subject;
lblTheme.Text = sequence.Category;
lblDeadline.Text = sequence.DueDate;
for (int i = 0; i < sequence.Difficulty; i++) {
stars [i].Visibility = ViewStates.Visible;
}
imgRightArrow.SetImageResource (Resource.Drawable.arrowRight);
imgSequenceBadge.SetImageResource (Resource.Drawable.imgVragenreeks);
}
}
the wierd part is: My images are shown correctly. Any Ideas?
EDIT: apparently in gridView and gridLayout the Textviews are set to white when not selected and to black if selected. Found it when it changed my theme to default.
Upvotes: 1
Views: 540
Reputation: 265
apparently in gridView and gridLayout the Textviews are set to white when not selected and to black if selected. Found it when it changed my theme to default.
Upvotes: 1
Reputation: 5336
The ImageView
is showing up because you created a list with ImageView
as the element (stars = new List<ImageView> ();
). If you want to display both an ImageView
and a TextView
, I woudl suggest that you create a custom GridView
that displays a custom grid object. An excellent tutorial on how to accomplish this may be found here: http://www.learn2crack.com/2014/01/android-custom-gridview.html
Upvotes: 0