Android的附加复选框动态复选框、动态、Android

2023-09-13 01:49:10 作者:While i was still

下面是我的布局XMLS。现在我们拥有的复选框,在布局(listitem.xml)数量有限(7件)。而且,我们正在把它的线性布局。

main.xml中

 < XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:后台=#FFFFFF
   >

    <的LinearLayout
        机器人:ID =@ + ID / linearLayout1
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentLeft =真
        机器人:layout_alignParentTop =真
        机器人:layout_marginLeft =21dp
        机器人:layout_marginTop =38dp>

        <的TextView
            机器人:ID =@ + ID / textView1
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_alignBottom =@ + ID / linearLayout1
            机器人:layout_alignLeft =@ + ID / linearLayout1
            机器人:文本=测试
            机器人:文字颜色=#000000/>

        < AutoCompleteTextView
            机器人:ID =@ + ID / tester_name
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_weight =1
            机器人:EMS =10
            机器人:利用=人物
            机器人:文字颜色=#000000>

            <不是requestFocus />
        < / AutoCompleteTextView>

    < / LinearLayout中>

    <的TextView
        机器人:ID =@ + ID / textView2
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_below =@ + ID / linearLayout1
        机器人:layout_centerHorizo​​ntal =真
        机器人:layout_marginTop =19dp
        机器人:文本=APPS测试:
        机器人:textAppearance =机器人:ATTR / textAppearanceLarge
        机器人:文字颜色=#000000/>




    <查看
        机器人:ID =@ + ID /厂景
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =1DP
        机器人:layout_below =@ + ID / textView2
        机器人:后台=#CCCCCC
        机器人:layout_marginBottom =5DP/>

    <的ListView
        机器人:ID =@ + ID / apps_list
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentRight =真
        机器人:layout_below =@ + ID /厂景
        机器人:dividerHeight =5DP>
    < / ListView控件>

    <按钮
        机器人:ID =@ + ID / refreshBtn
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =40dp
        机器人:layout_alignBottom =@ + ID / textView2
        机器人:layout_alignParentLeft =真
        机器人:文本=刷新/>

< / RelativeLayout的>
 

listitem.xml

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:后台=#FFFFFF
    机器人:方向=垂直>

    <的LinearLayout
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT>

        <的TextView
            机器人:ID =@ + ID / APP_NAME
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_weight =70
            机器人:textAppearance =机器人:ATTR / textAppearanceMedium
            机器人:文字颜色=#000000/>

        <按钮
            机器人:ID =@ + ID / launch_btn
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_marginTop =4DP
            机器人:layout_weight =20
            机器人:文本=LAUNCH/>
    < / LinearLayout中>

    < RadioGroup中
        机器人:ID =@ + ID / status_group
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:方向=横向>

        <单选按钮
            机器人:ID =@ + ID / pass_btn
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:检查=真
            机器人:文本=PASS
            机器人:文字颜色=#000000/>

        <单选按钮
            机器人:ID =@ + ID / fail_btn
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:文本=不及格
            机器人:文字颜色=#000000/>
    < / RadioGroup中>

    <的LinearLayout
        机器人:ID =@ + ID / failure_layout
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:方向=垂直>

        <的TextView
            机器人:ID =@ + ID / textView1
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:可聚焦=假
            机器人:focusableInTouchMode =假
            机器人:重力=中心
            机器人:文本=失败原因
            机器人:textAppearance =机器人:ATTR / textAppearanceMedium
            机器人:文字颜色=#000000/>

        <的LinearLayout
            机器人:ID =@ + ID / failure_reasonslist
            机器人:layout_width =match_parent
            机器人:layout_height =WRAP_CONTENT
            机器人:可聚焦=假
            机器人:focusableInTouchMode =假
            机器人:方向=垂直>

            <复选框
                机器人:ID =@ + ID / failure_Sound
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:文字颜色=#000000/>

            <复选框
                机器人:ID =@ + ID / failure_GPS
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:可聚焦=假
                机器人:focusableInTouchMode =假
                机器人:文字颜色=#000000/>

            <复选框
                机器人:ID =@ + ID / failure_Display
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:可聚焦=假
                机器人:focusableInTouchMode =假
                机器人:文字颜色=#000000/>

            <复选框
                机器人:ID =@ + ID / failure_Network
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:可聚焦=假
                机器人:focusableInTouchMode =假
                机器人:文字颜色=#000000/>

            <复选框
                机器人:ID =@ + ID / failure_Rotation
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:可聚焦=假
                机器人:focusableInTouchMode =假
                机器人:文字颜色=#000000/>

            <复选框
                机器人:ID =@ + ID / failure_Microphone
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:可聚焦=假
                机器人:focusableInTouchMode =假
                机器人:文字颜色=#000000/>

            <复选框
                机器人:ID =@ + ID / failure_Others
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:可聚焦=假
                机器人:focusableInTouchMode =假
                机器人:文字颜色=#000000/>
        < / LinearLayout中>
    < / LinearLayout中>

    <的LinearLayout
        机器人:ID =@ + ID / lineatlayout1
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:方向=横向>

        <的TextView
            机器人:ID =@ + ID / textView2
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:文本=介绍:
            机器人:textAppearance =机器人:ATTR / textAppearanceMedium
            机器人:文字颜色=#000000/>

        <的EditText
            机器人:ID =@ + ID / description_text
            机器人:layout_width =match_parent
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_weight =1
            机器人:可点击=真
            机器人:EMS =10
            机器人:可聚焦=真
            机器人:focusableInTouchMode =真
            机器人:inputType =textMultiLine
            机器人:文字颜色=#000000>
        < /的EditText>
    < / LinearLayout中>
 <的LinearLayout
        机器人:ID =@ + ID / lineatlayout2
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:方向=横向>
    <按钮
        机器人:ID =@ + ID /的submit_btn
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文本=提交/>
    <按钮
        机器人:ID =@ + ID / uninstall_btn
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文本=卸载/>
    < / LinearLayout中>

    <! - < / RelativeLayout的> - >

< / LinearLayout中>
 

不过,按照新的要求,我们需要动态地添加的复选框。像需要从API调用获取的选项,并将其转换为在视图复选框。我花了很多时间在这上面。有人建议的方法来解决这个问题。

Android 动态实现密码 复选框等显示与隐藏

我们的布局应该是这样的。在列表视图中,我们显示员工详细信息,并为每个员工记录的资格应该从API调用或数据库加载。

  [点评名(可编辑)
               员工免得
---------------------------------------
Employee1 [点击我]

男(0)女()
薪水:5999(可编辑)
资格
[X] BA
[]理学士
[]高考
[ ]其他
[提交按钮]
---------------------------------------
和Employee2 [点击我]

男(0)女()
薪水:5999(可编辑)
资格
[X] BA
[]理学士
[]高考
[ ]其他
[提交按钮]
---------------------------------------
Employee3 [点击我]

男(0)女()
薪水:5999(可编辑)
资格
[X] BA
[]理学士
[]高考
[ ]其他
[提交按钮]
---------------------------------------
 

来源$ C ​​$ C

 私有类ListAdapters扩展ArrayAdapter< ApplicationBean中> {
    私人的ArrayList< ApplicationBean中>项目;
    私人诠释的位置;

    公共ListAdapters(上下文的背景下,INT textViewResourceId,
            ArrayList的< ApplicationBean中> mTitleList){
        超(背景下,textViewResourceId,mTitleList);
        this.items = mTitleList;
    }

    @覆盖
    公共查看getView(INT位置,查看convertView,ViewGroup中父){
        视图V = convertView;
        this.position =位置;
        如果(V == NULL){
            LayoutInflater充气=(LayoutInflater)mContext
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            V = inflater.inflate(R.layout.applicationlistitem,NULL);
        }

        最后ApplicationBean中O =(ApplicationBean中)items.get(位置);

        如果(O!= NULL){

            txtAppName =(TextView中)v.findViewById(R.id.app_name);
            txtAppName.setText(+ o.getAppName());
            launchButton =(按钮)v.findViewById(R.id.launch_btn);
            launchButton.setTag(位置);
            launchButton.setOnClickListener(新OnClickListener(){

                @覆盖
                公共无效的onClick(视图v){

                    最终PackageManager下午= mContext.getPackageManager();
                    意图LaunchIntent = PM
                            .getLaunchIntentForPackage(项目
                                    获得(的Integer.parseInt(v.getTag()
                                            的ToString()))getPname())。
                    mContext.startActivity(LaunchIntent);

                }
            });
            最后的LinearLayout failure_reasonslist =(的LinearLayout)V
                    .findViewById(R.id.failure_reasonslist);

            rdgPassFail =(RadioGroup中)v.findViewById(R.id.status_group);
            rdgPassFail.setTag(位置);

            单选passBtn =(单选)V
                    .findViewById(R.id.pass_btn);
            passBtn.setTag(位置);
            单选failbtn =(单选)V
                    .findViewById(R.id.fail_btn);
            failbtn.setTag(位置);

            rdgPassFail
                    .setOnCheckedChangeListener(新OnCheckedChangeListener(){

                        @覆盖
                        公共无效onCheckedChanged(RadioGroup中组,
                                INT checkedId){
                            ApplicationBean中O =(ApplicationBean中)项目
                                    获得(的Integer.parseInt(group.getTag()
                                            的ToString()));

                            开关(checkedId){
                            案例R.id.fail_btn:
                                Log.e(失败按钮,点击);
                                o.setFailState(真正的);
                                o.setPassState(假);
                                numOptions = 0;
                                Log.e(失败按钮 -  1,点击);

                                打破;
                            案例R.id.pass_btn:
                                Log.e(通过按钮,点击);

                                o.setFailState(假);
                                o.setPassState(真正的);
                                Log.e(通过按钮----- 1,点击);

                                打破;
                            }
                            items.set(的Integer.parseInt(group.getTag()
                                    的ToString()),O);
                        }

                    });

            的LinearLayout featuresTable =(的LinearLayout)v.findViewById(R.id.failure_reasonslist);

            //使用循环复选框特征1 =新的复选框(本);
            的for(int i = 0; I< = 5;我++){
                复选框特点1 =新的复选框(this.getContext());
                featuresTable.addView(特征);
            }




            txtDescription =(EditText上)V
                    .findViewById(R.id.description_text);
            txtDescription.setTag(位置);
            如果(txtDescription.isFocused()){
                InputMethodManager inputManager =(InputMethodManager)mContext
                        .getSystemService(INPUT_METHOD_SERVICE);
                inputManager.restartInput(txtDescription);
            }

            txtDescription
                    .setOnFocusChangeListener(新View.OnFocusChangeListener(){

                        @覆盖
                        公共无效onFocusChange(视图V,布尔hasFocus){
                            如果(!hasFocus){

                                最后的EditText标题=(EditText上)V;
                                o.setDescription(Caption.getText()
                                        的ToString());

                            }

                        }
                    });
            uninstallButton =(按钮)v.findViewById(R.id.uninstall_btn);
            uninstallButton.setTag(位置);
            // uninstallButton.setVisibility(View.INVISIBLE);
            o.setUninstallVisible(假);
            uninstallButton.setOnClickListener(新OnClickListener(){

                @覆盖
                公共无效的onClick(视图v){
                    乌里packageUri = Uri.parse(套餐
                            + items.get(
                                    的Integer.parseInt(v.getTag()的toString()))
                                    .getPname());
                    意图uninstallIntent =新的意图(
                            Intent.ACTION_DELETE,packageUri);
                    uninstallIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(uninstallIntent);
                    mTitleList.remove(items.get((整数)v.getTag()));

                    mListView.setAdapter(新ListAdapters(mContext,
                            R.id.app_name,mTitleList));
                    ((BaseAdapter)mListView.getAdapter())
                            .notifyDataSetChanged();
                    isUninstallclicked = TRUE;

                }
            });

            提交按钮=(按钮)v.findViewById(R.id.submit_btn);
            submitButton.setTag(txtDescription);
            submitButton.setOnClickListener(新OnClickListener(){

                @覆盖
                公共无效的onClick(视图v){
                    // TODO自动生成方法存根
                    EditText上电视=(EditText上)v.getTag(); //获取的EditText
                                                            // 目的

                    txtDescription =电视;
                    如果(txtTesterName.getText()。的toString()。等于()){
                        的ShowDialog(请输入测试仪的名字,
                                mContext);
                    }否则,如果(numOptions == 0){
                        的ShowDialog(请选择失败的原因,mContext);
                    }否则,如果(tv.getText()的toString()。等于()){
                        的ShowDialog(请输入描述,mContext);
                    }否则如果(!isNetworkAvailable()){

                        的ShowDialog(
                                没有网络connection.Report不会提交
                                mContext);
                    } 其他 {

                        如果(!o.isUninstallVisible()){
                            uninstallButton.setVisibility(View.VISIBLE);
                            o.setUninstallVisible(真正的);
                            mListView.invalidate();
                        }
                        PostRequest P =新PostRequest(的Integer.parseInt(电视
                                。.getTag()的toString()));
                        p.execute();

                    }
                }

            });

        }
        返回伏;
    }
 

解决方案

 的LinearLayout featuresTable =(的LinearLayout)findViewById(R.id.failure_reasonslist);
//使用循环
复选框特点1 =新的复选框(本);
featuresTable.addView(特征);
 

The following are my layout xmls. Now we are have a limited number (seven) of check boxes in the layout (listitem.xml). And we are adding it in a linear layout.

main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:background="#FFFFFF"
   >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="21dp"
        android:layout_marginTop="38dp" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/linearLayout1"
            android:layout_alignLeft="@+id/linearLayout1"
            android:text="TESTER : "
            android:textColor="#000000" />

        <AutoCompleteTextView
            android:id="@+id/tester_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:capitalize="characters" 
            android:textColor="#000000">

            <requestFocus />
        </AutoCompleteTextView>

    </LinearLayout>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/linearLayout1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="19dp"
        android:text="APPS TO TEST : "
        android:textAppearance="?android:attr/textAppearanceLarge" 
        android:textColor="#000000"/>




    <View
        android:id="@+id/view1"
        android:layout_width="wrap_content"
        android:layout_height="1dp"
        android:layout_below="@+id/textView2"
        android:background="#CCCCCC" 
        android:layout_marginBottom="5dp"/>

    <ListView
        android:id="@+id/apps_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/view1" 
        android:dividerHeight="5dp">
    </ListView>

    <Button
        android:id="@+id/refreshBtn"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_alignBottom="@+id/textView2"
        android:layout_alignParentLeft="true"
        android:text="Refresh" />

</RelativeLayout>

listitem.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#FFFFFF"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/app_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="70"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#000000" />

        <Button
            android:id="@+id/launch_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:layout_weight="20"
            android:text="LAUNCH" />
    </LinearLayout>

    <RadioGroup
        android:id="@+id/status_group"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <RadioButton
            android:id="@+id/pass_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="PASS"
            android:textColor="#000000" />

        <RadioButton
            android:id="@+id/fail_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="FAIL"
            android:textColor="#000000" />
    </RadioGroup>

    <LinearLayout
        android:id="@+id/failure_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:gravity="center"
            android:text="FAILURE REASONS"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#000000" />

        <LinearLayout
            android:id="@+id/failure_reasonslist"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:orientation="vertical" >

            <CheckBox
                android:id="@+id/failure_Sound"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#000000" />

            <CheckBox
                android:id="@+id/failure_GPS"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:focusable="false"
                android:focusableInTouchMode="false"
                android:textColor="#000000" />

            <CheckBox
                android:id="@+id/failure_Display"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:focusable="false"
                android:focusableInTouchMode="false"
                android:textColor="#000000" />

            <CheckBox
                android:id="@+id/failure_Network"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:focusable="false"
                android:focusableInTouchMode="false"
                android:textColor="#000000" />

            <CheckBox
                android:id="@+id/failure_Rotation"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:focusable="false"
                android:focusableInTouchMode="false"
                android:textColor="#000000" />

            <CheckBox
                android:id="@+id/failure_Microphone"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:focusable="false"
                android:focusableInTouchMode="false"
                android:textColor="#000000" />

            <CheckBox
                android:id="@+id/failure_Others"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:focusable="false"
                android:focusableInTouchMode="false"
                android:textColor="#000000" />
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/lineatlayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="DESCRIPTION : "
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#000000" />

        <EditText
            android:id="@+id/description_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:clickable="true"
            android:ems="10"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:inputType="textMultiLine"
            android:textColor="#000000" >
        </EditText>
    </LinearLayout>
 <LinearLayout
        android:id="@+id/lineatlayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
    <Button
        android:id="@+id/submit_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="  SUBMIT " />
    <Button
        android:id="@+id/uninstall_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="UNINSTALL" />
    </LinearLayout>

    <!-- </RelativeLayout> -->

</LinearLayout>

But as per the new requirement we need to add the check boxes dynamically. Like need to fetch the options from the API call and convert it as check boxes in the view. I spent lots of time in it. Can someone suggest a method to solve this.

Our layout should be like this. In a list view we are displaying employee details and for each employee record the qualification should be loaded from the API call or database.

      [Reviewer Name (Editable)]       
               Employee Lest           
---------------------------------------
Employee1                    [Click Me]

Male (0)          Female ( )
Salary : [5999 (editable)]
Qualification
[X]BA
[ ]BSc
[ ]Matriculation
[ ]Other
[Submit Button]
---------------------------------------
Employee2                    [Click Me]

Male (0)          Female ( )
Salary : [5999 (editable)]
Qualification
[X]BA
[ ]BSc
[ ]Matriculation
[ ]Other
[Submit Button]
---------------------------------------
Employee3                    [Click Me]

Male (0)          Female ( )
Salary : [5999 (editable)]
Qualification
[X]BA
[ ]BSc
[ ]Matriculation
[ ]Other
[Submit Button]
---------------------------------------

Source code

private class ListAdapters extends ArrayAdapter<ApplicationBean> {
    private ArrayList<ApplicationBean> items;
    private int position;

    public ListAdapters(Context context, int textViewResourceId,
            ArrayList<ApplicationBean> mTitleList) {
        super(context, textViewResourceId, mTitleList);
        this.items = mTitleList;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        this.position = position;
        if (v == null) {
            LayoutInflater inflater = (LayoutInflater) mContext
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = inflater.inflate(R.layout.applicationlistitem, null);
        }

        final ApplicationBean o = (ApplicationBean) items.get(position);

        if (o != null) {

            txtAppName = (TextView) v.findViewById(R.id.app_name);
            txtAppName.setText("" + o.getAppName());
            launchButton = (Button) v.findViewById(R.id.launch_btn);
            launchButton.setTag(position);
            launchButton.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {

                    final PackageManager pm = mContext.getPackageManager();
                    Intent LaunchIntent = pm
                            .getLaunchIntentForPackage(items
                                    .get(Integer.parseInt(v.getTag()
                                            .toString())).getPname());
                    mContext.startActivity(LaunchIntent);

                }
            });
            final LinearLayout failure_reasonslist = (LinearLayout) v
                    .findViewById(R.id.failure_reasonslist);

            rdgPassFail = (RadioGroup) v.findViewById(R.id.status_group);
            rdgPassFail.setTag(position);

            RadioButton passBtn = (RadioButton) v
                    .findViewById(R.id.pass_btn);
            passBtn.setTag(position);
            RadioButton failbtn = (RadioButton) v
                    .findViewById(R.id.fail_btn);
            failbtn.setTag(position);

            rdgPassFail
                    .setOnCheckedChangeListener(new OnCheckedChangeListener() {

                        @Override
                        public void onCheckedChanged(RadioGroup group,
                                int checkedId) {
                            ApplicationBean o = (ApplicationBean) items
                                    .get(Integer.parseInt(group.getTag()
                                            .toString()));

                            switch (checkedId) {
                            case R.id.fail_btn:
                                Log.e("Fail button", "Clicked");
                                o.setFailState(true);
                                o.setPassState(false);
                                numOptions = 0;
                                Log.e("Fail button--1", "Clicked");

                                break;
                            case R.id.pass_btn:
                                Log.e("Pass button", "Clicked");

                                o.setFailState(false);
                                o.setPassState(true);
                                Log.e("Pass button-----1", "Clicked");

                                break;
                            }
                            items.set(Integer.parseInt(group.getTag()
                                    .toString()), o);
                        }

                    });

            LinearLayout featuresTable = (LinearLayout) v.findViewById(R.id.failure_reasonslist);

            // use loop CheckBox feature1 = new CheckBox(this); 
            for(int i = 0; i<=5; i++) {
                CheckBox feature1 = new CheckBox(this.getContext());
                featuresTable.addView(feature1);
            }




            txtDescription = (EditText) v
                    .findViewById(R.id.description_text);
            txtDescription.setTag(position);
            if (txtDescription.isFocused()) {
                InputMethodManager inputManager = (InputMethodManager) mContext
                        .getSystemService(INPUT_METHOD_SERVICE);
                inputManager.restartInput(txtDescription);
            }

            txtDescription
                    .setOnFocusChangeListener(new View.OnFocusChangeListener() {

                        @Override
                        public void onFocusChange(View v, boolean hasFocus) {
                            if (!hasFocus) {

                                final EditText Caption = (EditText) v;
                                o.setDescription(Caption.getText()
                                        .toString());

                            }

                        }
                    });
            uninstallButton = (Button) v.findViewById(R.id.uninstall_btn);
            uninstallButton.setTag(position);
            // uninstallButton.setVisibility(View.INVISIBLE);
            o.setUninstallVisible(false);
            uninstallButton.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    Uri packageUri = Uri.parse("package:"
                            + items.get(
                                    Integer.parseInt(v.getTag().toString()))
                                    .getPname());
                    Intent uninstallIntent = new Intent(
                            Intent.ACTION_DELETE, packageUri);
                    uninstallIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(uninstallIntent);
                    mTitleList.remove(items.get((Integer) v.getTag()));

                    mListView.setAdapter(new ListAdapters(mContext,
                            R.id.app_name, mTitleList));
                    ((BaseAdapter) mListView.getAdapter())
                            .notifyDataSetChanged();
                    isUninstallclicked = true;

                }
            });

            submitButton = (Button) v.findViewById(R.id.submit_btn);
            submitButton.setTag(txtDescription);
            submitButton.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    EditText tv = (EditText) v.getTag(); // get edittext
                                                            // object

                    txtDescription = tv;
                    if (txtTesterName.getText().toString().equals("")) {
                        showDialog("Please enter the name of tester",
                                mContext);
                    } else if (numOptions == 0) {
                        showDialog("Please select failure reason", mContext);
                    } else if (tv.getText().toString().equals("")) {
                        showDialog("Please enter the description", mContext);
                    } else if (!isNetworkAvailable()) {

                        showDialog(
                                "No network connection.Report won't be submitted",
                                mContext);
                    } else {

                        if (!o.isUninstallVisible()) {
                            uninstallButton.setVisibility(View.VISIBLE);
                            o.setUninstallVisible(true);
                            mListView.invalidate();
                        }
                        PostRequest p = new PostRequest(Integer.parseInt(tv
                                .getTag().toString()));
                        p.execute();

                    }
                }

            });

        }
        return v;
    }

解决方案

LinearLayout featuresTable = (LinearLayout) findViewById(R.id.failure_reasonslist);
// use loop 
CheckBox feature1 = new CheckBox(this);
featuresTable.addView(feature1 );

 
精彩推荐
图片推荐