Reputation: 87
I have an Android app that returns a ListView
of football fixtures from a Firebase database. The list works at present but I'd like to improve the UI. The image below shows what I have and what I'd like to achieve;
On the lefthand side I have a layout xml that loops through the records and displays the date per record, but what I want to do is return a list that displays fixtures under 1 date if they are the same and if not then display under the new date (as on the righthand side).
Below is the layout of my xml;
To give you an idea of the code (please ask if you'd like to see the code, I got marked down over posting 50 lines recently);
<TextView
android:id="@+id/txtDate"
android:layout_width="0dp"
android:layout_height="24dp"
android:background="#ff0000"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:textColor="@color/cardview_light_background"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="dateofmatch" />
The date red header is inside the listview xml.
I'm guessing this is a recursive function that works out all of the children of a date and then draws out the list.
My question is, which approach would you recommend as I don't want to kill performance and I'm torn between 2-3 ways I could do this.
EDIT: Adapter for the ListView
public class matchList extends ArrayAdapter<matches> {
private Activity context;
private List<matches> matchList;
public matchList(Activity context, List<matches> matcheslist) {
super(context, R.layout.match_layout, matcheslist);
this.context = context;
this.matchList = matcheslist;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View listViewItem = inflater.inflate(R.layout.match_layout, null, true);
TextView textViewDate = (TextView) listViewItem.findViewById(R.id.txtDate);
TextView textGameID = (TextView) listViewItem.findViewById(R.id.txtGameID);
TextView textViewTime = (TextView) listViewItem.findViewById(R.id.txtTime);
TextView textViewHomeTeam = (TextView) listViewItem.findViewById(R.id.txtAction);
TextView textViewAwayTeam = (TextView) listViewItem.findViewById(R.id.txtAwayTeam);
TextView textViewPitchNo = (TextView) listViewItem.findViewById(R.id.txtPitch);
ImageView imgLiveIco = (ImageView) listViewItem.findViewById(R.id.imgLive);
matches match = matchList.get(position);
textViewDate.setText(match.getDate());
textGameID.setText(match.getGameID());
textViewHomeTeam.setText(match.getHomeTeam());
textViewAwayTeam.setText(match.getAwayTeam());
textViewTime.setText(match.getTime());
String fdate = helper.dateFormater(match.getDate() , "EE dd MMM yyyy" , "dd/MM/yyyy");
textViewDate.setText(fdate);
textViewPitchNo.setText("Pitch " + match.getPitch().toString());
if(match.getPlayed() == 1) {
imgLiveIco.setVisibility(View.VISIBLE);
} else {
imgLiveIco.setVisibility(View.INVISIBLE);
}
return listViewItem;
}
}
Upvotes: 1
Views: 570
Reputation: 1
To achieve what you want, I recommend you use a simple if statement. What I don't understand from your code is the fact that the dateofmatch
is apart of the entire item view or not. If it is apart of that view, then you need to find that view using findViewById()
method and use the if statement like this:
if (dateOfPreviousMatch.equals(dateOfMath)) {
//set visibility of dateofmatch to GONE
} else {
//set visibility of dateofmatch to VISIBLE
}
Upvotes: 1