我刚创建了一个警告对话框,通过点击列表视图中的项目显示,我认为创建了一个Recycler Adapter包含一个checl box项目,警报对话框显示良好但没有复选框项目我不知道为什么它没有& #39; t给我任何错误,因为它显示为enter image description here
这是调用Recycle Adapter类的部分
private static void setPiking(String modeCode) {
RecyclerView modifierItemList;
Button OkBtn, CancelBtn;
LayoutInflater inflater2 = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
View view2 = inflater2.inflate(R.layout.modifier_list, null);
modifierItemList = (RecyclerView) view2.findViewById(R.id.modifierList);
OkBtn = (Button) view2.findViewById(R.id.okBtn90);
CancelBtn = (Button) view2.findViewById(R.id.cancelBtn90);
final AlertDialog.Builder builder1 = new AlertDialog.Builder(new ContextThemeWrapper(context, R.style.myDialog));
ModGroubeCode = Integer.parseInt(modeCode);
String Sql = "SELECT dbo.Items.Code, dbo.Items.Name FROM dbo.Items";
ResultSet RS = ConnectionClass.Ret_RS(Sql);
try {
ArrayList<ItemsListsModel> modifierArrayList = new ArrayList<ItemsListsModel>();
while (RS.next()) {
builder1.setMessage("Modifier Group :- " + RS.getString("ModifierGroup_Name"));
String name = RS.getString("Name");
String id = RS.getString("Code");
TreeMap<String, Object> arr = new TreeMap<String, Object>();
ItemsListsModel itemsListsModel = new ItemsListsModel(id, name, arr);
modifierArrayList.add(itemsListsModel);
}
adapter = new RecycleAdapterDialogModifier(context, modifierArrayList);
modifierItemList.setAdapter(adapter);
builder1.setView(view2);
builder1.setCancelable(true);
final AlertDialog alert11 = builder1.create();
OkBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
CancelBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alert11.dismiss();
}
});
alert11.show();
if (Mo_multiPick) {
//show Ok
OkBtn.setVisibility(View.VISIBLE);
} else {
OkBtn.setVisibility(View.INVISIBLE);
}
if (Mo_allawNoPick) {
//show Cancel
CancelBtn.setVisibility(View.VISIBLE);
} else {
CancelBtn.setVisibility(View.INVISIBLE);
}
} catch (Exception ex) {
}
}
这是我的Recycle Adapter.class
package abtech.waiteriano.com.waitrer.adapters;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;
import java.util.ArrayList;
import abtech.waiteriano.com.waitrer.R;
import abtech.waiteriano.com.waitrer.getters_and_setters.ItemsListsModel;
/**
* Created by yassin on 5/17/17.
*/
public class RecycleAdapterDialogModifier extends RecyclerView.Adapter<RecycleAdapterDialogModifier.MyViewHolder> {
private Context context;
ArrayList<ItemsListsModel> modifierArrayList;
public RecycleAdapterDialogModifier(Context context, ArrayList<ItemsListsModel> modifierArrayList) {
this.context = context;
this.modifierArrayList = modifierArrayList;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.modifierlistitem, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
ItemsListsModel itemsListsModel = modifierArrayList.get(position);
holder.modifierCB.setText(itemsListsModel.getName());
}
@Override
public int getItemCount() {
return modifierArrayList.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
CheckBox modifierCB;
TextView usernameContItem;
public MyViewHolder(View itemView) {
super(itemView);
modifierCB = (CheckBox) itemView.findViewById(R.id.itemCb);
}
}
}
希望这会很清楚
答案 0 :(得分:0)
只需设置回收站视图layoutManager
即可modifierItemList.setLayoutManager(new LinearLayoutManager(context));