イベントリスナに対応した実装を作成 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,8 +8,23 @@ 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> {
ArrayList<ListItem> listItems;
LacertaSelectDirDialogEventListener listener;
public SelectDirDialogItemAdapter(LacertaSelectDirDialogEventListener listener) {
this.listener = listener;
}
public void setListItems(ArrayList<ListItem> listItems) {
this.listItems = listItems;
}
@Override @Override
public SelectDirDialogItemAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { public SelectDirDialogItemAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.common_list_item, parent, false); View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.common_list_item, parent, false);
@ -18,13 +33,17 @@ public class SelectDirDialogItemAdapter extends RecyclerView.Adapter<SelectDirDi
@Override @Override
public void onBindViewHolder(SelectDirDialogItemAdapter.ViewHolder holder, int position) { public void onBindViewHolder(SelectDirDialogItemAdapter.ViewHolder holder, int position) {
holder.title.setText("title"); ListItem listItem = listItems.get(position);
holder.description.setText("description"); holder.title.setText(listItem.getTitle());
holder.description.setText(listItem.getDescription());
holder.itemView.setOnClickListener(v -> {
listener.onDirSelected(listItem.getTitle(), listItem.getItemId());
});
} }
@Override @Override
public int getItemCount() { public int getItemCount() {
return 100; return listItems.size();
} }
public class ViewHolder extends RecyclerView.ViewHolder { public class ViewHolder extends RecyclerView.ViewHolder {