From ac2001142f4df39f4074bfcc89f0402a5b00cb0a Mon Sep 17 00:00:00 2001 From: nero Date: Tue, 19 Dec 2023 10:15:33 +0900 Subject: [PATCH] =?UTF-8?q?Laibrary=E3=81=8C=E8=A1=A8=E7=A4=BA=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=82=B3=E3=83=BC?= =?UTF-8?q?=E3=83=89=E3=82=92=E6=9B=B8=E3=81=8D=E6=8F=9B=E3=81=88=E3=81=9F?= =?UTF-8?q?=E3=80=82=20=E3=83=BBnull=E3=82=92=E6=A4=9C=E5=87=BA=E3=81=97?= =?UTF-8?q?=E3=81=A6=E5=AE=89=E5=85=A8=E6=80=A7=E3=82=92=E9=AB=98=E3=82=81?= =?UTF-8?q?=E3=81=9F=20=E3=83=BBRecyclerView.Adapter=E3=82=92=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E3=81=99=E3=82=8B=E3=81=9F=E3=82=81=E3=81=AE=E3=82=B3?= =?UTF-8?q?=E3=83=BC=E3=83=89=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/misc.xml | 1 - .../feature/library/LibraryTopFragment.java | 79 +++++++++++++++---- 2 files changed, 63 insertions(+), 17 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 9f71c83d..773fe0fb 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryTopFragment.java b/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryTopFragment.java index 0ce9b739..081605a7 100644 --- a/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryTopFragment.java +++ b/feature/library/src/main/java/one/nem/lacerta/feature/library/LibraryTopFragment.java @@ -2,13 +2,17 @@ package one.nem.lacerta.feature.library; import android.os.Bundle; +import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ListView; +import android.widget.TextView; import java.util.ArrayList; import java.util.List; @@ -60,29 +64,72 @@ public class LibraryTopFragment extends Fragment { } } + + public class DocumentAdapter extends RecyclerView.Adapter { + + private List documentList; + + public DocumentAdapter(List documentList) { + this.documentList = documentList; + } + + @NonNull + @Override + public DocumentViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(android.R.layout.simple_list_item_1, parent, false); + return new DocumentViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull DocumentViewHolder holder, int position) { + holder.bind(documentList.get(position)); + } + + @Override + public int getItemCount() { + return documentList.size(); + } + + class DocumentViewHolder extends RecyclerView.ViewHolder { + private final TextView textView; + + DocumentViewHolder(View itemView) { + super(itemView); + textView = itemView.findViewById(android.R.id.text1); + } + + void bind(String document) { + textView.setText(document); + } + } + + } + @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment - View view = inflater.inflate(R.layout.fragment_library_top, container, false); + View view = inflater.inflate(R.layout.fragment_library_top, container, false); // Use view.findViewById instead of findViewById - ListView documentListView = view.findViewById(R.id.document_list); - List documentList = new ArrayList<>(); + RecyclerView documentRecyclerView = view.findViewById(R.id.document_list); - documentList.add("Document A"); - documentList.add("Document B"); - documentList.add("Document C"); - // レイアウトリソースを指定する(例: simple_list_item_1) - ArrayAdapter adapter = new ArrayAdapter<>( - getActivity(), // 修正: requireActivity() ではなく getActivity() を使用 - android.R.layout.simple_list_item_1, - documentList); + if (documentRecyclerView != null) { + List documentList = new ArrayList<>(); + documentList.add("Document A"); + documentList.add("Document B"); + documentList.add("Document C"); - documentListView.setAdapter(adapter); + // Create and set the adapter + DocumentAdapter adapter = new DocumentAdapter(documentList); + documentRecyclerView.setAdapter(adapter); - return view; - } + // Use a LinearLayoutManager to specify the layout + LinearLayoutManager layoutManager = new LinearLayoutManager(requireContext()); + documentRecyclerView.setLayoutManager(layoutManager); + } + + return view; + } } \ No newline at end of file