jXl
라이브러리를 사용하여 Excel 시트로 채워지는 사용자 지정 listView가 있습니다. 모두 잘 작동하지만 하나 이상의 ListView Item을 선택할 때 자동으로 8-9 항목 뒤에 다른 목록보기 항목에서도 선택됩니다. 예를 들어 radioButton1
이 인덱스 0
에서 선택되는 경우 radioButton1
이 선택되면 표시됩니다. 색인 8
.다른 사용자 지정 ListView에서 RadioButton 선택 점프가 자동으로 선택됩니다.
public class CustomListView extends ArrayAdapter<ListModel> {
Context context;
private List<ListModel> studentsList;
ListModel listModel;
TextView name, date;
RadioGroup radioGroup;
RadioButton presentRDOButton, absentRDOButton, leaveRDOButton;
LayoutInflater inflater;
public static List<ListModel> attenList = new ArrayList<ListModel>();
final JExcelClass jXl = new JExcelClass();
boolean flagPres = true;
boolean flagAbsen = true;
boolean flagLeave = true;
public AttendanceCustomListView(Context context, int resource,
List<ListModel> studentsList) {
super(context, resource, studentsList);
this.context = context;
this.studentsList = studentsList;
}
private class ViewHolder {
TextView name, date;
RadioGroup radioGroup;
RadioButton presentRDOButton, absentRDOButton, leaveRDOButton;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
final int pos = position + 1;
// inflater = (LayoutInflater) context
// .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
inflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.layout_list_content, null);
holder = new ViewHolder();
// initialization here
holder.name = (TextView) convertView.findViewById(R.id.nameListTV);
holder.date = (TextView) convertView.findViewById(R.id.dateTV);
holder.radioGroup = (RadioGroup) convertView
.findViewById(R.id.attendanceRDG);
holder.presentRDOButton = (RadioButton) convertView
.findViewById(R.id.presentRDO);
holder.absentRDOButton = (RadioButton) convertView
.findViewById(R.id.absentRDO);
holder.leaveRDOButton = (RadioButton) convertView
.findViewById(R.id.leaveRDO);
holder.radioGroup
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group,
int checkedId) {
int getPosition = (Integer) group.getTag();
studentsList.get(getPosition). //problem here
switch (checkedId) {
case R.id.presentRDO:
//code goes here
break;
}
}
});
및 에서는 CustomClass이
public class CustomClass extends Activity {
ListView listView;
List<ListModel> listModel;
CustomListView attendanceCustomListView;
JExcelClass jXl;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_listview);
listView = (ListView) findViewById(R.id.list);
listModel = new ArrayList<ListModel>();
jXl = new JExcelClass();
List<String> abc = jXl.readExcelSheet("test.xls");
String date = this.getDate();
for (String temp : abc) {
listModel.add(new ListModel(temp, date));
}
attendanceCustomListView = new AttendanceCustomListView(this,
R.layout.layout_list_content, listModel);
listView.setAdapter(attendanceCustomListView);
}
}
좀 더 많은 정보가 필요하면 알려 주시기 바랍니다 CustomListView : 다음은 내 코드입니다. 감사.
내 문제가
RadioGroup
통해 RadioButton
을 설정하는 방법을 지금 코드 업데이트?
다음을 제거하십시오. if (convertView == null) – mmlooloo
@mmlooloo를 제거하면 문제가 악화됩니다. –
제거했을 때 무슨 일이 일어 났습니까? 이 문제는 convertView의 재활용으로 인해 발생하므로 첫 번째 단계에서 문제를 해결하는 첫 번째 단계라고 생각합니다. 첫 번째 단계에서는 재활용 된보기를 사용하지 못하게합니다! – mmlooloo