这篇博客是我在android studio学习过程中记录的不能解决的问题。(红色标记的是问题)
package com.example.alex.topreview.NotePad;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.support.v7.widget.RecyclerView;
import android.view.MenuItem;
import com.example.alex.topreview.R;
import java.util.*;
public class NotePadActivity extends AppCompatActivity {
private Toolbar tb1;
private RecyclerView rv1;
private recycleAdapater mrecyclerAdapter;
public static List<filelist> mDatas;
// private String[] mDatas={"qweqw","qwe"};
private filelist f1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_note_pad);
tb1=findViewById(R.id.toolbar);
setSupportActionBar(tb1);
tb1.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId())
{
case R.id.setting:
Intent intent=new Intent(NotePadActivity.this,SettingActivity.class);
startActivity(intent);
break;
}
return false;
}
});
mDatas = new ArrayList<filelist>(); //为什么这里要转成ArrayList
// filelist fl;
// String zt;
// for ( int i=0; i < 40; i++) {
// if (i%2==0){
// zt="已阅读";
// }else{;
// zt="未阅读";
// }
// fl=new filelist("item"+i,zt);
// mDatas.add(fl);
// }
// 1.0的实验内容
// 用mDatas.add()方法添加元素只能保存一个。
mrecyclerAdapter=new recycleAdapater(this,mDatas);
rv1=findViewById(R.id.recycleview1);
rv1.setHasFixedSize(true);
rv1.setLayoutManager(new LinearLayoutManager(NotePadActivity.this));
rv1.setAdapter(mrecyclerAdapter);
rv1.setItemAnimator(new DefaultItemAnimator());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu,menu);
return super.onCreateOptionsMenu(menu);
}
}