mercredi 18 décembre 2019

select one checkbox and uncheck another checkbox which is checked

While running code get this Error Message: what i am trying to do is select any checkbox, but when clicking to any other checkbox the first checkbox remain clicked only so i want i can only select one checkbox at a time not to or there like radio button checkbox.

Traceback (most recent call last):
File "C:/Projects/SmartTesterPython/PidStop.py", line 457, in <module>
ui.setupUi(Dialog)
File "C:/Projects/SmartTesterPython/PidStop.py", line 186, in setupUi
self.printAll_checkBox.stateChanged.connect(self.onStateChange)
TypeError: connect() failed between stateChanged(int) and onStateChange()

code goes here:

self.printAll_checkBox.stateChanged.connect(self.onStateChange)
self.printFail_checkBox.stateChanged.connect(self.onStateChange)

@pyqtSlot(int)
def onStateChange(self, state):
    if state == Qt.Checked:
    if self.sender() == self.printAll_checkBox:
       self.printFail_checkBox.setChecked(False)
       self.printNothing_checkBox.setChecked(False)
       self.printPassFail_checkBox.setChecked(False)
    elif self.sender() == self.printFail_checkBox:
       self.printAll_checkBox.setChecked(False)
       self.printNothing_checkBox.setChecked(False)
       self.printPassFail_checkBox.setChecked(False)



ListView Checked Checkboxes

I am creating an Android application for communication learning

i make a List of word, it is contains a CheckBoxes and TextView, TextView is to display the the word, the use of the CheckBox is to determine what item in the ListView that I selected.

i store the id of the word in sqlite with "submit" button. when i close and open the activity again i want to see the checked checkboxes but this code only save to my database but not show the selected item when i open the activity again

this is the Activity

public class PerkembanganLevel1 extends AppCompatActivity{

    private ContentDao contentDao;
    private ChildDao childDao;
    private Child anakYangDipilih;

    public Global global;

    private AssessmentDao assessmentDao;
    private Assessment assessment;

    String idYangSudahBisa;

    PerkembanganAdapter perkembanganAdapter = null;

    ContentHistory contentHistory;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_perkembangan_level1);

        contentDao = new ContentDao(this);
        contentDao.open();

        childDao = new ChildDao(this);
        childDao.open();

        anakYangDipilih = ((Global) getApplicationContext()).getChild();

        idYangSudahBisa = anakYangDipilih.getLevel1();

        ArrayList<ContentHistory> listKataLevel1 = (ArrayList<ContentHistory>) contentDao.getAllWordByLevel(1);

        perkembanganAdapter = new PerkembanganAdapter(this, R.layout.list_perkembangan, listKataLevel1);

        ListView level1 =  findViewById(R.id.LVPlv1);
        level1.setAdapter(perkembanganAdapter);
        Log.i("listKataLevel1 ", String.valueOf(listKataLevel1));
        level1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                contentHistory = (ContentHistory) parent.getItemAtPosition(position);

            }
        });
        findViewById(R.id.BtnPLv1Submit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                idYangSudahBisa = perkembanganAdapter.idYangSudahBisa();

                anakYangDipilih.getId();
                anakYangDipilih.setLevel1(idYangSudahBisa);
                anakYangDipilih.setCreatedBy(((Global) getApplicationContext()).getTherapist().getId());
                anakYangDipilih.setUpdatedBy(((Global) getApplicationContext()).getTherapist().getId());
                anakYangDipilih.setCreatedDate(new Date());
                anakYangDipilih.setUpdatedDate(new Date());
                anakYangDipilih = childDao.saveChild(anakYangDipilih);

                Toast.makeText(PerkembanganLevel1.this, "Perkembangan Anak pada level 1 Berhasil Diperbarui", Toast.LENGTH_SHORT).show();
            }
        });


    }

}

this is the adapter


public class PerkembanganAdapter extends ArrayAdapter<ContentHistory> {


    String idYangSudahBisa;

    private ChildDao childDao;
    private Child anakYangDipilih;

    public ArrayList<ContentHistory> contentHistories;

    public PerkembanganAdapter(Context context, int id, ArrayList<ContentHistory> contentHistories){
        super(context, id, contentHistories);
        this.contentHistories = new ArrayList<>();
        this.contentHistories.addAll(contentHistories);



        childDao = new ChildDao(getContext());
        childDao.open();

        anakYangDipilih = ((Global) context.getApplicationContext()).getChild();
        this.idYangSudahBisa = anakYangDipilih.getLevel1();

    }

    private class ViewHolder{
        TextView title;
        CheckBox checkBoxes;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {

        ViewHolder viewHolder = null;
        if (convertView == null){
            LayoutInflater layoutInflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = layoutInflater.inflate(R.layout.list_perkembangan, null);

            viewHolder = new ViewHolder();
            viewHolder.title = convertView.findViewById(R.id.TVListPerkembangan);
            viewHolder.checkBoxes = convertView.findViewById(R.id.CBListPerkembangan);

            convertView.setTag(viewHolder);

            viewHolder.checkBoxes.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    CheckBox checkBox = (CheckBox) v;
                    ContentHistory contentHistory = (ContentHistory) checkBox.getTag();
                    contentHistory.setSelected(checkBox.isChecked());
                    if (checkBox.isChecked()){
                        idYangSudahBisa = idYangSudahBisa + ","+contentHistory.getId();
                        //Toast.makeText(getContext(), ""+idYangSudahBisa,Toast.LENGTH_SHORT).show();
                    } else {
                        idYangSudahBisa = idYangSudahBisa.replace(","+contentHistory.getId(), "");
                        //Toast.makeText(getContext(), ""+idYangSudahBisa,Toast.LENGTH_SHORT).show();
                    }

                }
            });



        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }


        ContentHistory contentHistory = contentHistories.get(position);
        viewHolder.title.setText(contentHistory.getTitle());

        viewHolder.checkBoxes.setChecked(contentHistory.getSelected());
        viewHolder.checkBoxes.setTag(contentHistory);


        return convertView;

    }

    public String idYangSudahBisa(){

        return this.idYangSudahBisa;
    }

}
...



mardi 17 décembre 2019

React Native CheckBox and FlatList: Cannot Toggle, and can only select each item once

I am using import CheckBox from '@react-native-community/checkbox';.

I am only able to 'select' each 'item' once and cannot toggle it (change or re-toggle).

Any help would be appreciated and if there's alternate plugins/packages available feel free to suggest it.

Code snippet below:

 import CheckBox from '@react-native-community/checkbox';

 export default class FrCreateScreen extends Component {

    constructor(props) {
        super(props);
        this.state = {
            timeSlots: [
                { id: '1', time: '10am - 11am' },
                { id: '2', time: '11am - 12pm' },
                { id: '3', time: '12pm - 1pm' },
                { id: '4', time: '1pm - 2pm' },
                { id: '5', time: '2pm - 3pm' },
                { id: '6', time: '3pm - 4pm' },
                { id: '7', time: '4pm - 5pm' },
                { id: '8', time: '5pm - 6pm' },
            ],

            //checkBox
            checked: false,
        }
    }

    checkBox(value) {
        this.setState({
            checked: !value,
        })
    }

    getAppointmentTimePage() {
        const { checked, timeSlots } = this.state;

        return (
            <View>
                <Text style={[styles.title, { marginTop: 20 }]}>Select Appointment Time:</Text>
                {<FlatList
                    data={timeSlots}
                    keyExtractor={(times) => times.id}
                    renderItem={({ item }) => {
                        return (
                            <View style={styles.containerTime}>
                                <Text style={styles.textTime}>{item.time}</Text>
                                <CheckBox
                                    value={checked}
                                    onChange={() => this.checkBox(item.id)}
                                />
                            </View>
                        );
                    }}
                />}
                <TouchableOpacity style={styles.addContainer}>
                    <Text style={styles.addText}>Add Appointment</Text>
                </TouchableOpacity>
            </View>
        );
    }

    render() {
        return (
            <ScrollView>
                {this.getAppointmentTimePage()}
            </ScrollView>
        )
    };
};

Image Screenshot below:




How to make select all check box work in kotlin? [duplicate]

This question is an exact duplicate of:

There are 5 recyclerview items. When I clicked SelectAll, just first item's checkbox drawable change. I want make all item's checkbox drawable will be change. How to make select all check box work in kotlin??

class CartViewActivity : AppCompatActivity(), SwipeRefreshLayout.OnRefreshListener {

    private val tag = this::class.java.simpleName

    lateinit var adapter: CartItemRecyclerAdapter

  var itemList: MutableList<CartItemDataVo> = arrayListOf()


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_cart_view)

    SelectAll.setOnClickListener {

      if(SelectAll.isChecked){
         SelectAll.buttonDrawable=it.context.getDrawable(R.drawable.check_box_active_cs)
         checkBox.buttonDrawable=it.context.getDrawable(R.drawable.check_box_active_cs)

          else {
          SelectAll.buttonDrawable= it.context.getDrawable(R.drawable.check_box_no)
          checkBox.buttonDrawable= it.context.getDrawable(R.drawable.check_box_no)

        }

        }
       swipeRefreshLo.setOnRefreshListener(this)


        itemList.add(CartItemDataVo("item1", 1, 16800, "cart_doll"))
        itemList.add(CartItemDataVo("item2", 1, 16800, "cart_cup"))
        itemList.add(CartItemDataVo("item3", 1, 30000, "cart_perfume"))
        itemList.add(CartItemDataVo("item4", 1, 16800, "cart_fan"))
        itemList.add(CartItemDataVo("item5", 1, 16800, "cart_bear"))

        val itemRecyclerAdapter = CartItemRecyclerAdapter(this, this , itemList)

        recycler_view.adapter = itemRecyclerAdapter
        recycler_view.layoutManager = 
        androidx.recyclerview.widget.LinearLayoutManager(applicationContext)      
    }

    override fun onRefresh() {
        swipeRefreshLo.isRefreshing = false
    }
}
````



Rails: How to pass value "9999-99-99" to date if checkbox is checked?

I have a datepicker to :DATE and a "Unknown" checkbox aside. I need to pass "9999-99-99" to :DATE if checkbox is checked.

Here is my code.

1    <%= form.label :DATE %>
2    <%= form.datepicker :DATE %>
3    <div>
4      <label class="radio-inline"> <%=  form.check_box :DATE %> Unknown </label>
5    </div>

I also got an error for line 4:

undefined method 'to_i' for Thu, 19 Dec 2019:Date Did you mean? to_s.

In my database, :DATE is formatted as "YYYY-MM-DD".

Thanks.




I have multiple checkbox and stoting checkbox name into another table in db.but when i am updating checkbox i am facing problem in mvc

enter code here                

this is my view

@Html.LabelFor(model => model.ProductColor, htmlAttributes: new { @class = "control-label col-md-3" })* @for (int i = 0; i < Model.colorlist.Count(); i++) {

                        for (int j = 0; j < Model.checklist.Count(); j++)
                        {


                            if (Model.checklist[j].ColorName.Contains(Model.colorlist[i].ColorName))
                            {

                                @Html.CheckBoxFor(model => model.checklist[j].isColorselected)


                                }



                        }

                        @Html.DisplayFor(model => model.colorlist[i].ColorName)
                        @Html.HiddenFor(model => model.colorlist[i].ColorId)
                        @Html.HiddenFor(model => model.colorlist[i].ColorName)

                    }



store multiple check boxes in mysql from django form

I am not able to send the selected checkboxes value to mysql database. Please help me in finding out what i missed in the code. When i try to submit the form, it is just redirecting to the same form without any errors and in the same way it is not storing the values in database.

views.py

def personview(request):  
    if request.method == "POST": 
        form =PersonForm(request.POST)
        print(request.POST.getlist('choosetopics[]'))
        if form.is_valid():  
            try:
                form.save()


            except:  
                print("not valid")  
    else:  
        form = PersonForm()  

    return render(request,'person_list.html',{'form':form}) 


models.py

class Person(models.Model):
    name = models.ForeignKey(CollegeAttributes, on_delete=models.SET_NULL, null=True)
    domain = models.ForeignKey(Domains, on_delete=models.SET_NULL, null=True)
    choosetopics = models.ForeignKey(domain_topics, on_delete=models.SET_NULL, null=True)

    def __str__(self):
        return self.name