listview在Android中升序

时间:2017-09-07 21:30:28

标签: android database sorting listview firebase

我在这个项目中工作,但我不知道如何反向显示列表视图(升序)

Artistlist类

public class Artistlist extends ArrayAdapter<Artist> {

private Activity context;
private List<Artist> artistList;

public Artistlist(Activity context,List<Artist> artistList){
    super(context,R.layout.list_layout , artistList);

    this.context = context;
    this.artistList = artistList;


}

@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    LayoutInflater inflater = context.getLayoutInflater();

    View listViewItem = inflater.inflate(R.layout.list_layout,null,true);

    TextView textViewname = (TextView) listViewItem.findViewById(R.id.textView);
    TextView textViewGener = (TextView) listViewItem.findViewById(R.id.textView2);

    Artist artist = artistList.get(position);

    textViewname.setText(artist.getArtistName());
    textViewGener.setText(artist.getArtistGener());

    return listViewItem;
}

}

如何反向显示列表视图(升序) 谢谢

1 个答案:

答案 0 :(得分:0)

在将列表发送到适配器之前使用此行代码

Collections.reverse(artistList);