我的复选框似乎不是CheckBox的实例

use*_*923 2 java checkbox android instanceof

根据我的论文,我在LogCat中发出警告,我认为这可能会影响我的代码.

我收到一个包含一些数据的JSON,我必须以编程方式使用checkbox和radiobutton(在RadioGroup中)进行布局.后来我可以投票这个调查,这是我的问题因为我在我的布局中getChildAt()

if(child instanceof CheckBox)
Run Code Online (Sandbox Code Playgroud)

不起作用,我不明白为什么.

这是我的代码:

 ll = (LinearLayout) findViewById(R.id.llSurvey);  //OnCreate

    /*Creating CheckBox*/
            String votes = jObj.getString("votes");
            String label = jObj.getString("label");
            String usid = jObj.getString("USID");    
            if(uType.equals("multi")){
                CheckBox cb = new CheckBox(SingleSurvey.this);
                cb.setText(label + " (" + votes + ")");
                cb.setId(s+1000);
                ll.addView(cb);         
                Log.i("MULTI_TYPE", "usid: " + usid + " id: " + cb.getId());
            }
            s++;

    /*Voting*/

            for(int i = 0; i < ll.getChildCount(); i++){
                View child = ll.getChildAt(i);
                int p = child.getId();
                Log.i("CHILD ID", "id: " + p);

                if(child instanceof TextView){
                    continue;
                }

                else if(child instanceof CheckBox){
                    Log.i("INSTANCE OF CB", "checkbox");
                    CheckBox cb = (CheckBox) child;
                    if(cb.isChecked()){
                        int cbId = cb.getId();
                        usid = rb_usid[cbId];
                        Log.i("CHECKBOX", "usid: " + usid);
                    }
                }

                //some other stuff
            }
Run Code Online (Sandbox Code Playgroud)

Mik*_* M. 7

Checkbox班是一个TextView子类,因此您的代码将不会进入else if块,这是什么警告说.

    android.widget.TextView
       ?android.widget.Button
           ?android.widget.CompoundButton
               ?android.widget.CheckBox
Run Code Online (Sandbox Code Playgroud)