wxx
230
2020-02-23 15:59:36
0
460

No adapter attached; skipping layout 리사이클러뷰 에러



public class MainActivity extends AppCompatActivity  implements View.OnClickListener{
    static int sub_code = 100;
    Button button;
    String name;
    String write;
    ArrayList<Date> arrayList;
    Date date;
    MyAdapter myAdapter;
    LinearLayoutManager linearLayoutManager;
    RecyclerView recyclerView;
    Diary diary;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        linearLayoutManager = new LinearLayoutManager(this);
        recyclerView = findViewById(R.id.recycleview);
        button =  findViewById(R.id.start);
        button.setOnClickListener(this);
        arrayList = new ArrayList<>();
        diary = new Diary();




        }

    @Override
    public void onClick(View v) {

        Intent intent  = new Intent(this , Diary.class);
        startActivityForResult(intent , sub_code);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode == sub_code && resultCode == RESULT_OK){
          name = data.getStringExtra("이름");
          write = data.getStringExtra("내용");
          date = new Date(0 , name , 0);
          arrayList.add(date);
           myAdapter = new MyAdapter(arrayList);
            linearLayoutManager = new LinearLayoutManager(this);
            recyclerView.setLayoutManager(linearLayoutManager);
           recyclerView.setAdapter(myAdapter);

        }
    }
}
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.CustomViewHolder> {

    private ArrayList<Date> arrayList;//데이터를 담을 배열

    public MyAdapter(ArrayList<Date> arrayList) {
        this.arrayList = arrayList;
    }




    @NonNull
    @Override
    public CustomViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycleview,parent,false);
        CustomViewHolder holder = new CustomViewHolder(view);

        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull final CustomViewHolder holder, int position) {
        holder.name.setText(arrayList.get(position).getName());;

    }

    @Override
    public int getItemCount() {
        return arrayList.size();
    }

    public class CustomViewHolder extends RecyclerView.ViewHolder {
        protected TextView time;
        protected TextView name;
        public CustomViewHolder(@NonNull View itemView) {
            super(itemView);

            time = (TextView)itemView.findViewById(R.id.time);//시간
            name = (TextView)itemView.findViewById(R.id.name);//이름;



        }
    }
}

온바인드뷰홀더 메소드안에 이름만 텍스트로 우선 출력을 해해볼려고 하는데 No adapter attached; skipping layout  이 ㅇ
에러가 뜨네요....어댑터연결문제인 것 같은데 코드상 문제가 없어 보이는데 뭐가 문제일까요,실행했을 때 텍스트뷰가
안보입니다


0
  • 답변 0

  • 로그인을 하시면 답변을 등록할 수 있습니다.