mirror of
https://github.com/lacerta-doc/Lacerta.git
synced 2024-11-23 00:13:16 +00:00
Adapter実装 WIP
This commit is contained in:
parent
8ca05fe454
commit
1515e53484
|
@ -0,0 +1,78 @@
|
|||
package one.nem.lacerta.component.common;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import one.nem.lacerta.model.document.tag.DocumentTag;
|
||||
|
||||
public class LacertaApplyTagAdapter extends RecyclerView.Adapter<LacertaApplyTagAdapter.LacertaApplyTagViewHolder>{
|
||||
|
||||
// Listener
|
||||
public interface LacertaApplyTagDialogListener {
|
||||
void itemChecked(View view, int position);
|
||||
void itemUnchecked(View view, int position);
|
||||
}
|
||||
|
||||
// Variables
|
||||
private ArrayList<DocumentTag> documentTagArrayList;
|
||||
private LacertaApplyTagDialogListener listener;
|
||||
|
||||
// Setter
|
||||
public LacertaApplyTagAdapter setListener(LacertaApplyTagDialogListener listener) {
|
||||
this.listener = listener;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LacertaApplyTagAdapter setDocumentTagArrayList(ArrayList<DocumentTag> documentTagArrayList) {
|
||||
this.documentTagArrayList = documentTagArrayList;
|
||||
return this;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
public LacertaApplyTagAdapter(ArrayList<DocumentTag> documentTagArrayList) {
|
||||
this.documentTagArrayList = documentTagArrayList;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public LacertaApplyTagAdapter.LacertaApplyTagViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.lacerta_dialog_apply_tag, parent, false);
|
||||
return new LacertaApplyTagAdapter.LacertaApplyTagViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull LacertaApplyTagAdapter.LacertaApplyTagViewHolder holder, int position) {
|
||||
DocumentTag documentTag = documentTagArrayList.get(position);
|
||||
holder.checkBox.setText(documentTag.getName());
|
||||
holder.checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
if (isChecked) {
|
||||
listener.itemChecked(buttonView, position);
|
||||
} else {
|
||||
listener.itemUnchecked(buttonView, position);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return documentTagArrayList == null ? 0 : documentTagArrayList.size();
|
||||
}
|
||||
|
||||
public class LacertaApplyTagViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
CheckBox checkBox;
|
||||
|
||||
public LacertaApplyTagViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
|
||||
checkBox = itemView.findViewById(R.id.checkBox);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user