set length of text in gridview items

This commit is contained in:
Chumva 2018-03-05 14:51:23 +02:00
parent 38954241c3
commit 9e334a0be3

View file

@ -41,7 +41,14 @@ public class TransportStopRouteAdapter extends ArrayAdapter<TransportStopRoute>
TransportStopRoute transportStopRoute = getItem(position); TransportStopRoute transportStopRoute = getItem(position);
if (transportStopRoute != null) { if (transportStopRoute != null) {
TextView transportStopRouteTextView = (TextView) convertView.findViewById(R.id.transport_stop_route_text); TextView transportStopRouteTextView = (TextView) convertView.findViewById(R.id.transport_stop_route_text);
transportStopRouteTextView.setText(transportStopRoute.route.getRef()); String routeNumber = transportStopRoute.route.getRef();
if (routeNumber.length() > 4) {
routeNumber = routeNumber.substring(0, Math.min(routeNumber.length(), 4));
}
if (routeNumber.contains(":")) {
routeNumber = routeNumber.substring(0, routeNumber.lastIndexOf(':'));
}
transportStopRouteTextView.setText(routeNumber);
GradientDrawable gradientDrawableBg = (GradientDrawable) transportStopRouteTextView.getBackground(); GradientDrawable gradientDrawableBg = (GradientDrawable) transportStopRouteTextView.getBackground();
gradientDrawableBg.setColor(transportStopRoute.getColor(app, nightMode)); gradientDrawableBg.setColor(transportStopRoute.getColor(app, nightMode));
} }