android - RecyclerView 根本不刷新
问题描述
我的 RecyclerView 没有更新。即使我调用 adapterNotifyDataSetChanged().Questions,并且答案已正确加载,但回收站中的项目却没有。
它们只是保持不变,甚至没有重新排序。
主要活动
public class MainActivity extends AppCompatActivity implements MyRecyclerViewAdapter.ItemClickListener {
MyRecyclerViewAdapter adapter;
EditText edit;
Button provjeri;
List<Item> questions;
int curquestion=0;
TextView pitanje;
public List<String> suggestSource = new ArrayList<>();
public static char[] user_submit_answer;
public char[]answeri;
String corect_answer;
// data to populate the RecyclerView with
String[]data = {"a","b","c","č","ć","d","đ","e","f","g","h","i","j","k","l","m"
,"n","o","p","r","s","š","t","u","v","z","ž"};
String[]simpleArray;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edit=findViewById(R.id.editText);
provjeri=findViewById(R.id.button);
pitanje=findViewById(R.id.textView);
Random random=new Random();
questions=new ArrayList<>();
for(int i=0;i<Database.questions.length;i++){
questions.add(new Item(Database.questions[i], answers[i]));
}
pitanje.setText(questions.get(curquestion).getQuestion());
// data to populate the RecyclerView with
// String[]data = {"a","b","c","č","ć","d","đ","e","f","g","h","i","j","k","l","m"
// ,"n","o","p","r","s","š","t","u","v","z","ž"};
corect_answer=(questions.get(curquestion).getAnswer());
answeri=corect_answer.toCharArray();
user_submit_answer=new char[answeri.length];
suggestSource.clear();
for(char item:answeri)
{
//Add logo name to list
suggestSource.add(String.valueOf(item));}
for(int i = answeri.length; i< answeri.length*2; i++){
suggestSource.add(data[random.nextInt(data.length)]);
}
Collections.shuffle(suggestSource);
simpleArray = new String[ suggestSource.size() ];
suggestSource.toArray( simpleArray );
// set up the RecyclerView
final RecyclerView recyclerView = findViewById(R.id.recyclerView);
int numberOfColumns = 6;
recyclerView.setLayoutManager(new GridLayoutManager(this, numberOfColumns));
adapter = new MyRecyclerViewAdapter(this, simpleArray);
adapter.setClickListener(this);
recyclerView.setAdapter(adapter);
adapter.notifyDataSetChanged();
provjeri.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(edit.getText().toString().equalsIgnoreCase(questions.get(curquestion).getAnswer())){
curquestion++;
pitanje.setText(questions.get(curquestion).getQuestion());
corect_answer=(questions.get(curquestion).getAnswer());
adapter.notifyDataSetChanged();
Toast.makeText(MainActivity.this,"blblblbl",Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(MainActivity.this,"netacno",Toast.LENGTH_SHORT).show();
}
}
});
//("btw:why must write so much unnecesary text,to accept my question"and still not enough to post question,so wtf i must write some novel here,maybe make up some problems thath do not even exist,or just ....wtf maaaaaaaaan)//
解决方案
由于没有人回答,我自己找到了答案。所以问题是我更新后没有刷新适配器,并且在创建之前调用了它
推荐阅读
- php - 无法打开流或文件:无法打开流:权限被拒绝
- c# - 如何在 C# 中将列表转换为 JSON?
- azure - 使用 Application Insight 时的操作 ID
- angular - 检查 FormGroup 上的模式验证器
- javascript - 仅在触摸字段时如何显示错误?| 反应 && 形式
- django - Django: ProtectedError exception handling is not working
- phpspreadsheet - How to draw or implement a pie chart using phpspreadsheet?
- r - 使用向量的元素位置作为 ID 号的向量到数据框
- javascript - Magneto Shoplift JavaScript 恶意代码
- python-3.x - How to read CSV File dwnloaded from NSE