我有一个RecyclerView列表,在我的数据库中显示一些数据。 如何将它打印的RecyclerView位置隐藏到我没有绑定到它的textView,并且某些文本视图不会显示在屏幕上
我试图实现这个目标
这里是破碎的布局
这是我的RecyclerView适配器
public class LogsAdapter extends RecyclerView.Adapter<LogsAdapter.ViewHolder> {
private List<LogsModel> logList;
private Context mContext;
private RecyclerView mRecyclerV;
public class ViewHolder extends RecyclerView.ViewHolder {
public TextView txtDate;
public TextView txtTimeIn;
public TextView txtTimeOut;
public TextView txtDivision;
public TextView txtDesignation;
public TextView txtActivities;
public TextView txtDepartment;
public View layout;
public ViewHolder(View v) {
super(v);
layout = v;
txtDate = (TextView) v.findViewById(R.id.txtDate);
txtTimeIn = (TextView) v.findViewById(R.id.txtTimeIn);
txtTimeOut = (TextView) v.findViewById(R.id.txtTimeOut);
txtDivision = (TextView) v.findViewById(R.id.txtDivision);
txtDesignation = (TextView) v.findViewById(R.id.txtDesignation);
txtActivities = (TextView) v.findViewById(R.id.txtActivities);
txtDepartment = (TextView) v.findViewById(R.id.txtDepartment);
}
}
public void add(int position, LogsModel logs) {
logList.add(position, logs);
notifyItemInserted(position);
}
public void remove(int position, LogsModel logs) {
logList.add(position, logs);
notifyItemRemoved(position);
}
public LogsAdapter(List<LogsModel> taskSet, Context context, RecyclerView recyclerView) {
logList = taskSet;
mContext = context;
mRecyclerV = recyclerView;
}
@Override
public LogsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View v = inflater.inflate(R.layout.layout, parent, false);
ViewHolder vh = new ViewHolder(v);
return vh;
}
@Override
public void onBindViewHolder(ViewHolder holder, final int position) {
final LogsModel logs = logList.get(position);
holder.txtDate.setText(logs.getDate());
holder.txtTimeIn.setText(logs.getTime_in());
holder.txtTimeOut.setText(logs.getTime_out());
holder.txtDivision.setText(logs.getDivision());
holder.txtDesignation.setText(logs.getDesignation());
holder.txtDepartment.setText(logs.getDepartment());
holder.txtActivities.setText(logs.getLog_content());
holder.layout.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setTitle("Choose Option");
builder.setMessage("Update or delete user?");
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.setPositiveButton("Update", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//go to update activity
// goToUpdateActivity(logs.getId());
}
});
builder.setNeutralButton("Delete", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
JournalDB db = new JournalDB(mContext);
db.deleteTask(logs.getDate());
logList.remove(position);
mRecyclerV.removeViewAt(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position, logList.size());
notifyDataSetChanged();
}
});
builder.create().show();
}
});
}
@Override
public int getItemCount() {
return logList.size();
}
}