イベントリスナに対応した実装を作成 WIP

This commit is contained in:
ろむねこ 2024-01-25 12:06:21 +09:00
parent a815d3b1b4
commit 03d78b1200
No known key found for this signature in database
GPG Key ID: FA1F39A1BA37D168
2 changed files with 53 additions and 31 deletions

View File

@ -23,7 +23,10 @@ public class LacertaSelectDirDialog extends DialogFragment {
RecyclerView recyclerView = view.findViewById(R.id.select_dir_recycler_view); RecyclerView recyclerView = view.findViewById(R.id.select_dir_recycler_view);
recyclerView.setHasFixedSize(true); recyclerView.setHasFixedSize(true);
SelectDirDialogItemAdapter adapter = new SelectDirDialogItemAdapter(); SelectDirDialogItemAdapter adapter = new SelectDirDialogItemAdapter((name, itemId) -> {
Toast.makeText(getContext(), "Called", Toast.LENGTH_SHORT).show();
dismiss();
});
recyclerView.setAdapter(adapter); recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new androidx.recyclerview.widget.LinearLayoutManager(getContext())); recyclerView.setLayoutManager(new androidx.recyclerview.widget.LinearLayoutManager(getContext()));

View File

@ -8,37 +8,56 @@ import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import one.nem.lacerta.model.ListItem;
public class SelectDirDialogItemAdapter extends RecyclerView.Adapter<SelectDirDialogItemAdapter.ViewHolder> { public class SelectDirDialogItemAdapter extends RecyclerView.Adapter<SelectDirDialogItemAdapter.ViewHolder> {
@Override ArrayList<ListItem> listItems;
public SelectDirDialogItemAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { LacertaSelectDirDialogEventListener listener;
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.common_list_item, parent, false);
return new SelectDirDialogItemAdapter.ViewHolder(view); public SelectDirDialogItemAdapter(LacertaSelectDirDialogEventListener listener) {
} this.listener = listener;
}
@Override
public void onBindViewHolder(SelectDirDialogItemAdapter.ViewHolder holder, int position) { public void setListItems(ArrayList<ListItem> listItems) {
holder.title.setText("title"); this.listItems = listItems;
holder.description.setText("description"); }
}
@Override
@Override public SelectDirDialogItemAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
public int getItemCount() { View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.common_list_item, parent, false);
return 100; return new SelectDirDialogItemAdapter.ViewHolder(view);
} }
public class ViewHolder extends RecyclerView.ViewHolder { @Override
public void onBindViewHolder(SelectDirDialogItemAdapter.ViewHolder holder, int position) {
TextView title; ListItem listItem = listItems.get(position);
TextView description; holder.title.setText(listItem.getTitle());
holder.description.setText(listItem.getDescription());
holder.itemView.setOnClickListener(v -> {
public ViewHolder(@NonNull View itemView) { listener.onDirSelected(listItem.getTitle(), listItem.getItemId());
super(itemView); });
}
title = itemView.findViewById(R.id.item_title);
description = itemView.findViewById(R.id.item_description); @Override
public int getItemCount() {
} return listItems.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView title;
TextView description;
public ViewHolder(@NonNull View itemView) {
super(itemView);
title = itemView.findViewById(R.id.item_title);
description = itemView.findViewById(R.id.item_description);
} }
}
} }