checkbox textview just work in emulator android -
i have problem , checkboxed textview work checked when click in emulator , if try on device , checkboxed textview not checked when click , blank .
my adapter :
import java.util.arraylist; import android.content.context; import android.support.v4.app.fragmentmanager; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.adapterview; import android.widget.adapterview.onitemselectedlistener; import android.widget.arrayadapter; import android.widget.checkbox; import android.widget.spinner; import android.widget.textview; import com.id.nirwana.r; import com.nirwana.app.models.amenities; public class amenitiesadapter extends arrayadapter<amenities> implements onitemselectedlistener { private context context; private int itemlayoutresource; spinner spinner; string[] menus; fragmentmanager fragmentmanager; public amenitiesadapter(context context, int itemlayoutresource, arraylist<amenities> items, fragmentmanager fragmentmanager) { super(context, itemlayoutresource, items); this.itemlayoutresource = itemlayoutresource; this.context = context; this.fragmentmanager = fragmentmanager; } @override public view getview(int position, view convertview, viewgroup parent) { // todo auto-generated method stub view view = convertview; if (view == null) { layoutinflater inflater = (layoutinflater) context .getsystemservice(context.layout_inflater_service); view = inflater.inflate(this.itemlayoutresource, null); } amenities amenities = getitem(position); textview name = (textview) view.findviewbyid(r.id.name); name.settext(amenities.getname()); checkbox cbox = (checkbox) view.findviewbyid(r.id.cbox); if (cbox != null) { if (amenities.getchecked()) { cbox.setchecked(true); } else { cbox.setchecked(false); } } return view; } @override public void onitemselected(adapterview<?> arg0, view arg1, int arg2, long arg3) { // todo auto-generated method stub } @override public void onnothingselected(adapterview<?> arg0) { // todo auto-generated method stub } }
my xml :
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <checkbox android:id="@+id/cbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:clickable="false" android:focusable="false" android:focusableintouchmode="false" /> <textview android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="end" android:marqueerepeatlimit="marquee_forever" android:maxlength="100" android:maxlines="1" android:scrollhorizontally="true" android:text="title" android:textappearance="?android:attr/textappearancelarge" android:textcolor="@color/title_item" android:textsize="15sp" android:textstyle="normal" /> </linearlayout>
my dialog :
package com.nirwana.app.fragments; import java.util.arraylist; import com.id.nirwana.r; import com.nirwana.app.adapters.amenitiesadapter; import com.nirwana.app.interfaces.selectamenitiescomunicator; import com.nirwana.app.models.amenities; import android.annotation.suppresslint; import android.app.activity; import android.app.alertdialog; import android.app.dialog; import android.support.v4.app.dialogfragment; import android.content.dialoginterface; import android.os.bundle; import android.view.view; import android.widget.adapterview; import android.widget.checkbox; import android.widget.listview; @suppresslint("validfragment") public class selectamenitiesdialog extends dialogfragment { arraylist<amenities> amenities; arraylist<amenities> selectedamenities; selectamenitiescomunicator listener; public selectamenitiesdialog() { // todo auto-generated constructor stub } public selectamenitiesdialog(arraylist<amenities> amenities) { // todo auto-generated constructor stub this.amenities = amenities; } @override public void onattach(activity activity) { // todo auto-generated method stub super.onattach(activity); listener = (selectamenitiescomunicator) activity; } @override public dialog oncreatedialog(bundle savedinstancestate) { // todo auto-generated method stub alertdialog.builder builder = new alertdialog.builder(getactivity()); selectedamenities = new arraylist<amenities>(); amenitiesadapter amenitiesadapter = new amenitiesadapter(getactivity() .getapplicationcontext(), r.layout.amenities_item_layout, amenities, getactivity().getsupportfragmentmanager()); listview list = new listview(getactivity()); list.setadapter(amenitiesadapter); list.setitemscanfocus(false); list.setchoicemode(listview.choice_mode_multiple); list.setonitemclicklistener(new adapterview.onitemclicklistener() { public void onitemclick(adapterview<?> arg0, view view, int arg2, long arg3) { // todo auto-generated method stub checkbox cbox = (checkbox) view.findviewbyid(r.id.cbox); if (cbox.ischecked()) { amenities.get(arg2).setchecked(false); selectedamenities.remove(amenities.get(arg2)); } else { amenities.get(arg2).setchecked(true); selectedamenities.add(amenities.get(arg2)); } ; } }); builder.settitle(getresources().getstring(r.string.select_amenities)) .setview(list) .setpositivebutton(r.string.ok_label, null) .setnegativebutton(r.string.cancel_label, new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int whichbutton) { } }); alertdialog dialog = builder.create(); dialog.show(); dialog.getbutton(alertdialog.button_positive).setonclicklistener( new view.onclicklistener() { public void onclick(view v) { // todo auto-generated method stub if (!selectedamenities.isempty()) { listener.getamenities(selectedamenities); dismiss(); } } }); return dialog; } }
Comments
Post a Comment