私のコード
private List<Object> mObjects;
private LongSparseArray<Account> uAccounts;
ImageView illustration;
TypefaceTextView explanation;
ProgressBar load;
ListView lv;
private Context context;
private AccountExpListAdapter accountExpListAdapter;
public int occurences;
private boolean allGood = true;
private void initUI() {
if (getActivity() != null && getActivity().getApplicationContext() != null) {
accountExpListAdapter = new AccountExpListAdapter(getActivity().getApplicationContext(),
mObjects);
if (lv != null) {
lv.setAdapter(accountExpListAdapter);
}
}
if (load != null)
load.setVisibility(View.GONE);
}
static class ViewHolder {
ImageView logo;
TextView tv;
RelativeLayout header;
RelativeLayout form;
CheckBox checkBox;
EditText email_ET;
EditText pwd_ET;
}
public class AccountExpListAdapter extends ArrayAdapter<Object> {
private List<Object> objects;
private Context context;
public AccountExpListAdapter(Context context, List<Object> objects) {
super(context, android.R.layout.simple_list_item_1, objects);
this.context = context;
this.objects = objects;
}
@Override
public int getCount() {
return objects.size();
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View vi = convertView;
ViewHolder holder;
if (vi == null) {
LayoutInflater inflater = LayoutInflater.from(context);
vi = inflater.inflate(R.layout.selectable, parent, false);
holder = new ViewHolder();
holder.logo = (ImageView) vi.findViewById(R.id.logo);
holder.tv = (TextView) vi.findViewById(R.id.name);
holder.header = (RelativeLayout) vi.findViewById(R.id.header);
holder.form = (RelativeLayout) vi.findViewById(R.id.form);
holder.checkBox = (CheckBox) vi.findViewById(R.id.box);
holder.email_ET = (EditText) vi.findViewById(R.id.email_edit_text);
holder.pwd_ET = (EditText) vi.findViewById(R.id.pwd_edit_text);
vi.setTag(holder);
} else {
holder = (ViewHolder) vi.getTag();
}
final Object object = objects.get(position);
Glide.with(context).load(Uri.parse(object.getLogo())).into(holder.logo);
holder.tv.setText(object.getName());
final ViewHolder finalHolder = holder;
holder.checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean isChecked = ((CheckBox) view).isChecked();
manageKeyboard(isChecked);
int visibility = isChecked ? View.VISIBLE : View.GONE;
finalHolder.form.setVisibility(visibility);
if (!isChecked) {
uAccounts.remove(object.getId());
} else {
uAccounts.put(object.getId(), new Account());
allGood = false;
lv.smoothScrollToPositionFromTop(position + 1, 150, 500);
finalHolder.email_ET.requestFocus();
}
}
});
holder.header.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finalHolder.checkBox.performClick();
}
});
if (holder.form != null) {
holder.email_ET.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
if (!checkEmailFormat(editable.toString())) {
finalHolder.email_ET.setError(getString(R.string.email_invalid));
allGood = false;
return;
} else {
allGood = true;
}
Long objectId = object.getId();
Account a;
if (uAccounts.indexOfKey(objectId) < 0) {
a = new Account();
} else {
a = uAccounts.get(objectId);
}
a.setUsername(editable.toString());
uAccounts.put(objectId, a);
}
});
holder.pwd_ET.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
if (editable.toString().length() == 0) {
finalHolder.pwd_ET.setError(getString(R.string.password_invalid));
allGood = false;
return;
} else {
allGood = true;
}
Long objectId = object.getId();
Account a;
if (uAccounts.indexOfKey(objectId) < 0) {
a = new Account();
} else {
a = uAccounts.get(objectId);
}
a.setEncrypted_password(editable.toString());
uAccounts.put(objectId, a);
}
});
}
return vi;
}
}
}
コードが原因の表示/非表示のフォームにチェックボックスのために非常に複雑ですが、それは、この不要なリストビューアイテムの挙動を生じることがないですか?
ありがとうございました
明らかに問題はあなたのコードにあります... – Selvin