0
其實我沒有得到大小,當我在android中打印Toast複選框Checked Event時。檢查所有子問題
這是我在父母的代碼複選框在Android中,如果我會得到的大小問題將自動解決。
此代碼在自定義適配器中聲明。
public void onBindViewHolder(final MyViewHolder holder, int position) {
//Toast.makeText(context, "Key: " + position, Toast.LENGTH_LONG).show();
String val = allCityList.get(position);
Integer cnt = val.split("-").length;
if (cnt > 1) {
val = val.split("-")[1];
holder.chkbox_parent.setText(val);
holder.chkbox_parent.setTag("State");
holder.chkbox_parent.setTypeface(null, Typeface.BOLD);
stateTag = val;
} else {
val = val.split("-")[0];
holder.chkbox_parent.setText(val);
holder.chkbox_parent.setTag(stateTag);
}
holder.chkbox_parent.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
CheckBox chk = (CheckBox) holder.chkbox_parent;
if (chk.getTag().equals("State")) {
String state = chk.getText().toString();
Toast.makeText(context, state, Toast.LENGTH_LONG).show();
try {
RecyclerView rv1 = holder.rvParent;
// Toast.makeText(context, ""+rv1.getTag(), Toast.LENGTH_LONG).show();
for (int i = 0; i < rv1.getChildCount(); i++) {
Log.e("hello......", ""+rv1.getChildCount());
CheckBox cb;
cb = (CheckBox) rv1.getChildAt(i).findViewById(R.id.chkbox_parent);
Toast.makeText(context, "" + cb.getText(), Toast.LENGTH_LONG).show();
// if (state.equals(cb.getTag()))
// cb.setChecked(chk.isChecked());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
問題上recyclerview未來即rv.getchildcount
請您詳細說明我理解的幾件事或者您能否給我演示程序。 – Abhi
我只提出違反您所做的RecyclerView API。我認爲,讓孩子數不是你想要的(常見的錯誤),你真正想做的是獲得/設置一些特定的項目狀態。說實話,你似乎沒有完全理解RecyclerView是如何工作的,並且在你不知道一些基本概念的情況下,我很難一步一步地解釋一切。你應該嘗試通過一個RecyclerView教程,像這樣:[link](http://www.androidhive.info/2016/01/android-working-with-recycler-view/)。它會幫助你理解回收概念。 –
我想你是對的,但我在代碼中顯示的是當我們檢查複選框所有子複選框被選中(全選)你有任何soln關於? – Abhi