-4

Actually I have list view, on touching list view I will get popup window of same list. Now I want to add check box. How can I add check box to below code. It would be great full if you help me along with modifying code.

Activity:

    listView1.setAdapter(adapter);
    adapter.notifyDataSetChanged();
    listView1.setOnTouchListener(new AdapterView.OnTouchListener()
    {

        @Override
        public boolean onTouch (View v, MotionEvent event){
        if (event.getAction() == MotionEvent.ACTION_UP) {


            dialog = new Dialog(PendingOrdersActitvity.this);
            dialog.setContentView(R.layout.itembumping);
            dialog.show();

            list1 = (ListView) dialog.findViewById(R.id.list1);
            adapter = new CustomAdapter(PendingOrdersActitvity.this, itemsList1);
            list1.setAdapter(adapter);
            list1.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {


                @Override
                public boolean onItemLongClick(AdapterView<?> parent, View view,
                                               int position, long id) {

                    for (int i = 0; i < itemsList1.size(); i++) {
                        if (i == position) {
                            view.setEnabled(false);
                            view.setClickable(false);
                            view.setBackgroundColor(Color.parseColor("#DCDBDB"));
                            adapter.notifyDataSetChanged();
                            ItemsBean bean = new ItemsBean();
                            bean.setInvNo(itemsList1.get(i).getInvNo());
                            bean.setItemnNameDisplay(itemsList1.get(i).getItemnNameDisplay());
                            bean.setLinenum(itemsList1.get(i).getLinenum());
                            bean.setQuantityDisplay(itemsList1.get(i).getQuantityDisplay());
                            bean.setProdnum(itemsList1.get(i).getProdnum());

                            newListitems.add(bean);

                        }
                    }
                    insertintodatabase(newListitems);

                    newListitems.clear();

                    return true;
                }
            }
        }
    }
Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
mallika
  • 1
  • 6
  • Possible duplicate of [AlertDialog with checkbox In android](http://stackoverflow.com/questions/16954196/alertdialog-with-checkbox-in-android) – SaravInfern Nov 21 '16 at 06:30
  • You have to add that check box in your customadapter layout file, then add boolean value in your ItemsBean class to get specific item checked, then get value from that bean class using position in your adapter class... You can refer this link:- http://stackoverflow.com/questions/11066846/android-get-checkbox-info-from-listview Or use this for reference:- https://android--code.blogspot.in/2015/08/android-alertdialog-multichoice.html – Bhavnik Nov 21 '16 at 06:32
  • Actually the issue is i use same Adapter for main llist and popup list if i add check box to adapter then it will come fpor main list too – mallika Nov 21 '16 at 06:37

1 Answers1

0

Try this:

  1. Add Check Box in CustomAdapter layout file.
  2. Modify class CustomAdapter,

    a. Add field and method,

    class CustomAdapter...{
        boolean mInDialog = false;
        .
        .
        .
        public void showCheckbox(boolean flag){
            mInDialog = true
        }
    }
    

    b. Modify getView(),

    CheckBox cb = (CheckBox) convertView.findViewById(R.id.checkbox);
    if(mInDialog){
        cb.setVisibility(View.VISIBLE);
    }else{
        cb.setVisibility(View.GONE);
    }
    
  3. Modify activity, before "list1.setAdapter(adpter)", add:

    adapter.showCheckbox(true);
    
  4. When dialog dismissed, add:

    adpater.showCheckbox(false);
    adapter.notifyDataSetChanged();
    

Hope this help!

i_A_mok
  • 2,744
  • 2
  • 11
  • 15