如何在 Java 中反转数组

我有一个应用程序的源代码,它显示在后端服务器中上传的值列表,但问题是它以相反的顺序显示值(首先列出上传的旧内容)我希望它正好相反(按日期) .


  public class SelectQuizActivity extends AppCompatActivity {


private static final String TAG = SelectQuizActivity.class.getSimpleName();


private int categoryId;

private String catName;

private String catImage;


private ImageView categoryImage;

private TextView categoryName;


private RecyclerView quizRecyclerView;


@Override

protected void onCreate(Bundle savedInstanceState) {

    requestWindowFeature(Window.FEATURE_NO_TITLE);

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_select_quiz);


    categoryId = getIntent().getExtras().getInt(Constants.CATEGORY);

    catName = getIntent().getExtras().getString(Constants.CATEGORY_NAME);

    catImage = getIntent().getExtras().getString(Constants.CATEGORY_IMAGE);


    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    if(getSupportActionBar() != null){

        getSupportActionBar().setElevation(0);

    }

    setTitle("");


    categoryImage = (ImageView)findViewById(R.id.quiz_category_image);

    categoryName = (TextView)findViewById(R.id.quiz_category_name);


    quizRecyclerView = (RecyclerView)findViewById(R.id.quiz_category);

    quizRecyclerView.setLayoutManager(new GridLayoutManager(SelectQuizActivity.this, 3));

    quizRecyclerView.setHasFixedSize(true);


    if(Helper.isNetworkAvailable(this)){

        allSubcategoryInCategory(catName);

    }else{

        DisplayMessage.displayErrorMessage(this, "No network available");

    }


}


上面的代码从类别适配器获取输入并将其显示为回收站视图


潇潇雨雨
浏览 218回答 3
3回答

小怪兽爱吃肉

首先调用这个Collections.reverse(arrayToListObject(response));然后CategoryAdapter mAdapter = new CategoryAdapter(SelectQuizActivity.this, arrayToListObject(response));                     quizRecyclerView.setAdapter(mAdapter);

手掌心

java.util.Collections.reverse(arrayToListObject(response))
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java