单选按钮选择跳是自动选择其他自定义的ListView [英] RadioButton selection jumps is auto selected on other Custom ListView

查看:186
本文介绍了单选按钮选择跳是自动选择其他自定义的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由Excel工作表使用锦绣丽库填充一个自定义的ListView。
一切工作正常,但是当我选择一个或多个ListView项,自动后8-9项选择我也选择其他ListView项。例如,如果 radioButton1 在选择首页 0 现在如果我向下滚动,我看到 radioButton1 在指数选择 8
这里是我的code:
CustomListView

I have a custom listView that is populated by Excel Sheet using jXl library. Everything works fine but when I select one or more ListView Item, automatically after 8-9 entries my selection is also selected on other ListView Item.. for example if radioButton1 is selected at index 0 now If I scroll down I see radioButton1 is selected at index 8. Here is my code: CustomListView

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);
    }
}

请让我知道,如果需要更多的信息。谢谢。

Please let me know If some more information is needed. Thanks.

更新了code
现在我的问题是如何设置单选 RadioGroup中

推荐答案

好吧!最后我得到了我的答案!
基本上所有我需要的是加3 静态最后变量,并用它们来保存单选按钮的状态点击。
请按照此<一个href=\"http://stackoverflow.com/questions/9392511/how-to-handle-oncheckedchangelistener-for-a-radiogroup-in-a-custom-listview-adap/9484222#9484222\">answer,这是最简单的答案都在互联网上。
感谢@hrishitiwari为指向的答案。

Okay! at last i got my answer! Basically all i needed was to add 3 static final variables and use them for saving the state of the radioButton clicked. Please follow this answer, this is the most simple answer all over the internet. Thanks @hrishitiwari for pointing to the answer.

这篇关于单选按钮选择跳是自动选择其他自定义的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆