@Override
public int getItemViewType(int position) {
int type = 0;
if (jcxtypeList.get(position).equals(TYPE_INPUT)) {
type = 0;
} else if (jcxtypeList.get(position).equals(TYPE_CONFIRM)) {
type = 1;
}
return type;
}
@Override
public int getViewTypeCount() {
return 2;
}
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(getActivity());
View view = null;
int type = getItemViewType(position);
switch (type) {
// 输入项
case 0:
view = inflater.inflate(R.layout.item_input, null);
TextView tvName = (TextView) view
.findViewById(R.id.tv_input_name);
final EditText etInputValue = (EditText) view
.findViewById(R.id.et_input_value);
etInputValue.setFocusable(true);
etInputValue.setFocusableInTouchMode(true);
tvName.setText((position + 1) + "、" + jcxnameList.get(position));
// 获取焦点
etInputValue.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
selectedPosition = position;
}
return false;
}
});
if (selectedPosition == position) {
// 如果当前的行下标和点击事件中保存的index一致,手动为EditText设置焦点。
etInputValue.requestFocus();
} else {
etInputValue.clearFocus();
}
etInputValue.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
hashMap.put(position, s.toString());
}
});
// 如果hashMap不为空,就设置的editText
if (hashMap.get(position) != null) {
etInputValue.setText(hashMap.get(position));
}
break;
// 确认项
case 1:
view = inflater.inflate(R.layout.item_confirm, null);
TextView tvConfirmName = (TextView) view
.findViewById(R.id.tv_confirm_name);
tvConfirmName.setText((position + 1) + "、"
+ jcxnameList.get(position));
RadioGroup rgConfirm = (RadioGroup) view
.findViewById(R.id.rg_confirm);
RadioButton rbtnYes = (RadioButton) view
.findViewById(R.id.rbtn_yes);
RadioButton rbtnNo = (RadioButton) view
.findViewById(R.id.rbtn_no);
RadioButton rbtnNotExist = (RadioButton) view
.findViewById(R.id.rbtn_not_exist);
rgConfirm.setFocusable(true);
rgConfirm.setFocusableInTouchMode(true);
rgConfirm.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
selectedPosition = position;
}
return false;
}
});
if (selectedPosition == position) {
// 如果当前的行下标和点击事件中保存的index一致,手动为EditText设置焦点。
rgConfirm.requestFocus();
} else {
rgConfirm.clearFocus();
}
rgConfirm
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group,
int checkedId) {
switch (checkedId) {
case R.id.rbtn_yes:
radioMap.put(position, 0);
break;
case R.id.rbtn_no:
radioMap.put(position, 1);
break;
case R.id.rbtn_not_exist:
radioMap.put(position, 2);
break;
default:
break;
}
}
});
// 如果hashMap不为空,就设置的editText
if (radioMap.get(position) != null) {
switch (radioMap.get(position)) {
case 0:
rgConfirm.check(R.id.rbtn_yes);
break;
case 1:
rgConfirm.check(R.id.rbtn_no);
break;
case 2:
rgConfirm.check(R.id.rbtn_not_exist);
break;
default:
break;
}
}
break;
default:
break;
}
public int getItemViewType(int position) {
int type = 0;
if (jcxtypeList.get(position).equals(TYPE_INPUT)) {
type = 0;
} else if (jcxtypeList.get(position).equals(TYPE_CONFIRM)) {
type = 1;
}
return type;
}
@Override
public int getViewTypeCount() {
return 2;
}
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(getActivity());
View view = null;
int type = getItemViewType(position);
switch (type) {
// 输入项
case 0:
view = inflater.inflate(R.layout.item_input, null);
TextView tvName = (TextView) view
.findViewById(R.id.tv_input_name);
final EditText etInputValue = (EditText) view
.findViewById(R.id.et_input_value);
etInputValue.setFocusable(true);
etInputValue.setFocusableInTouchMode(true);
tvName.setText((position + 1) + "、" + jcxnameList.get(position));
// 获取焦点
etInputValue.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
selectedPosition = position;
}
return false;
}
});
if (selectedPosition == position) {
// 如果当前的行下标和点击事件中保存的index一致,手动为EditText设置焦点。
etInputValue.requestFocus();
} else {
etInputValue.clearFocus();
}
etInputValue.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
hashMap.put(position, s.toString());
}
});
// 如果hashMap不为空,就设置的editText
if (hashMap.get(position) != null) {
etInputValue.setText(hashMap.get(position));
}
break;
// 确认项
case 1:
view = inflater.inflate(R.layout.item_confirm, null);
TextView tvConfirmName = (TextView) view
.findViewById(R.id.tv_confirm_name);
tvConfirmName.setText((position + 1) + "、"
+ jcxnameList.get(position));
RadioGroup rgConfirm = (RadioGroup) view
.findViewById(R.id.rg_confirm);
RadioButton rbtnYes = (RadioButton) view
.findViewById(R.id.rbtn_yes);
RadioButton rbtnNo = (RadioButton) view
.findViewById(R.id.rbtn_no);
RadioButton rbtnNotExist = (RadioButton) view
.findViewById(R.id.rbtn_not_exist);
rgConfirm.setFocusable(true);
rgConfirm.setFocusableInTouchMode(true);
rgConfirm.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
selectedPosition = position;
}
return false;
}
});
if (selectedPosition == position) {
// 如果当前的行下标和点击事件中保存的index一致,手动为EditText设置焦点。
rgConfirm.requestFocus();
} else {
rgConfirm.clearFocus();
}
rgConfirm
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group,
int checkedId) {
switch (checkedId) {
case R.id.rbtn_yes:
radioMap.put(position, 0);
break;
case R.id.rbtn_no:
radioMap.put(position, 1);
break;
case R.id.rbtn_not_exist:
radioMap.put(position, 2);
break;
default:
break;
}
}
});
// 如果hashMap不为空,就设置的editText
if (radioMap.get(position) != null) {
switch (radioMap.get(position)) {
case 0:
rgConfirm.check(R.id.rbtn_yes);
break;
case 1:
rgConfirm.check(R.id.rbtn_no);
break;
case 2:
rgConfirm.check(R.id.rbtn_not_exist);
break;
default:
break;
}
}
break;
default:
break;
}
return view;
}