Answer the question
In order to leave comments, you need to log in
Why is the list not showing up?
I'm trying to make a list. The code is this:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/datesList">
</ListView>
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/date" />
public class DatesAdapter extends ArrayAdapter<DateTime> {
private LayoutInflater inflater;
private int layout;
private ArrayList<DateTime> datesList;
private TextView date;
public DatesAdapter(@NonNull Context context, @LayoutRes int resource, ArrayList<DateTime> datesList) {
super(context, resource);
this.inflater = LayoutInflater.from(context);
this.layout = resource;
this.datesList = datesList;
}
@Override
public @NonNull View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
if (convertView == null){
convertView = inflater.inflate(this.layout, parent, false);
date = (TextView)convertView.findViewById(R.id.date);
}
date.setText(datesList.get(position).toString());
return convertView;
}
}
final ArrayList<DateTime> dates = new ArrayList<>();
dates.add(new DateTime(2017, 1, 1, 0, 0));
dates.add(new DateTime(2016, 1, 1, 0, 0));
dates.add(new DateTime(2015, 1, 1, 0, 0));
dates.add(new DateTime(2014, 1, 1, 0, 0));
DatesAdapter adapter = new DatesAdapter(this, R.layout.date_item, dates);
datesList.setAdapter(adapter);
Answer the question
In order to leave comments, you need to log in
It turns out that it was necessary to override the getCount method. I did not know.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question