Я недавно узнал об ArrayAdapters и пытаюсь использовать один в моем текущем приложении. Я использовал код, который я выучил ранее, но я сделал что-то не так. Вместо отображения полного списка отображается только 1 набор в списке. Я не уверен, что мне не хватает, чтобы отобразить полный список.
Мой xml выглядит так:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#6002EE">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/PageTitle"
android:text="@string/songs"
android:id="@+id/title"/>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/title">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/list">
</ListView>
</ScrollView>
...
</RelativeLayout>
А мой SongAdapter выглядит так:
public class SongAdapter extends ArrayAdapter {
public SongAdapter(Context context, ArrayList pWords) {
super(context,0, pWords);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Check if the existing view is being reused, otherwise inflate the view
View listItemView = convertView;
if(listItemView == null) {
listItemView = LayoutInflater.from(getContext()).inflate(
R.layout.list_item, parent, false);
}
Song my_word = (Song) getItem(position);
TextView songTextView = listItemView.findViewById(R.id.song);
songTextView.setText(my_word.getSongTitle());
TextView artistTextView = listItemView.findViewById(R.id.artist);
artistTextView.setText(my_word.getArtist());
return listItemView;
}
}
Я просто предполагаю, что это то, что нужно, чтобы выручить меня. Я очень новый. Я прочитал много страниц на ArrayAdapters, многие другие проблемы кажутся более сложными, чем эта. Я чувствую, что, может быть, мне не хватает какого-то кода?