listview Textview settext不适用于循环?

时间:2017-04-18 14:59:13

标签: android listview

listViewD.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> parent, View view,int position, long id) {

                            final CheckBox checkbox = (CheckBox) view.findViewById(R.id.checkbox);

                            if (edit)
                            {

                                Integer tempoid = tinydb.getInt("tempoid");
                                if (tempoid>0)
                                {
                                    tempoid1=tinydb.getListBoolean(""+tempoid);
                                    String tempoooo = tempoid1.toString();
                                    int calories3 = 0;
                                    int i;
                                    for (i = 0; i < foodListD.size(); i++)
                                    {
                                        View view1 = View.inflate(context, R.layout.textblack1,null);
                                        adapter.getView(i, view1, parent);
                                        CheckBox checkbox1 = (CheckBox) view1.findViewById(R.id.checkbox);
                                        TextView text = (TextView) view1.findViewById(R.id.calories);

                                        String tempoid2= String.valueOf(tempoid1.get(i));

                                        String calories1 = text.getText().toString();
                                        Integer calories2 = Integer.valueOf(calories1);

                                        if (tempoid1.get(i))
                                        {
                                            checkbox1.setChecked(tempoid1.get(i));
                                            text.setText("");


                                        }

                                    }
                                }
                            }

这是我的代码的一部分。我只是想知道为什么 text.setText(“”)似乎没有执行。我试图搜索并根据我搜索的内容,我需要使用adapter.notifyDataSetChanged()或invalidateViews()但它不起作用。顺便说一句,该代码可以按列表视图中的位置检索每个textview的值,所以我非常确定它是否有效。问题是它不适用于setText。我的代码出了什么问题?

编辑:顺便说一下,我的代码中的“tinydb”部分只是来自github的简化共享首选项。

0 个答案:

没有答案