好的,我正在尝试对从 XML 开始初始化的 recyclerView 进行排序。当我启动应用程序时,我可以看到电子邮件,也可以单击它们。排序按钮位于“设置”活动中,但每当我回到 RecyclerView 所在的主要活动时,单击该按钮后,我的 recyclerView 就会变成空白。
这是我的主要活动
package com.example.assignment_1;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
//Variables
private ArrayList<String> mNames = new ArrayList<>();
private ArrayList<String> mImageurls = new ArrayList<>();
private ArrayList<String> mHeaders = new ArrayList<>();
private ArrayList<String> mContent = new ArrayList<>();
static ArrayList<AssignmentEmail> emails = new ArrayList<>();
private RecyclerViewAdapdter adapter;
private RecyclerView recyclerView;
private Context mContext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EmailProvider emailProvider = new EmailProvider();
Context context = getApplicationContext();
if(emails.isEmpty() == true){
emails = emailProvider.getEmails(context);
loadEmails();
}
}
慕沐林林
墨色风雨
ITMISS
相关分类