android - how to get only item details to next activity to edit -
in list of bluetooth devices item names renamed , stored in database.when app starts should check database , if uuids same should display item list names.when click on item , goes next activity , click on settings option edit name of item , comes , first activty.it changes name names in listview changed edited name , names same got.
protected void onlistitemclick(listview l, view v, int position, long id) { final bluetoothdevice device = mledevicelistadapter.getdevice(position); if (device == null) return; log.v("_____________log", "localdevicename : "+mbluetoothadapter.getname()+" localdeviceaddress : "+mbluetoothadapter.getaddress()); log.v("___________log", "localdevicename : "+mbluetoothadapter.getname()+" localdeviceaddress : "+mbluetoothadapter.getaddress()); uuid deviceuuid = new uuid(device.hashcode(), ((long)device.hashcode() << 32) ); log.v("__________device uuid________","__________________"+deviceuuid); string deviceuuid = deviceuuid.tostring(); log.v("_______________________","___________________"+deviceuuid); intent intent = new intent(this, devicecontrolactivity.class); intent.putextra(devicecontrolactivity.extras_device_name, sname); intent.putextra(devicecontrolactivity.extras_device_address, device.getaddress());//} intent.putextra(devicecontrolactivity.extras_device_uuid, deviceuuid);//} if (mscanning) { mbluetoothadapter.stoplescan(mlescancallback); mscanning = false; } startactivity(intent); } public view getview(int i, view view, viewgroup viewgroup) { viewholder viewholder; // general listview optimization code. if (view == null) { view = minflator.inflate(r.layout.listitem_device, null); viewholder = new viewholder(); viewholder.deviceaddress = (textview) view.findviewbyid(r.id.device_address); viewholder.devicename = (textview) view.findviewbyid(r.id.device_name); view.settag(viewholder); } else { viewholder = (viewholder) view.gettag(); } bluetoothdevice device = mledevices.get(i); string devicename = device.getname(); uuid deviceuuid = new uuid(device.hashcode(), ((long)device.hashcode() << 32) ); log.v("__________device uuid________","__________________"+deviceuuid); string deviceid = deviceuuid.tostring(); log.v("_______________________","___________________"+deviceid); if (devicename != null && devicename.length() > 0){ db.open(); if(db!=null) { cursor c=db.getdata(); string selectquery = "select * devicedetails"; c = db.select(selectquery); while (c != null && c.movetonext()) { if (c.movetofirst()) { { if(deviceid.equalsignorecase(c.getstring(c.getcolumnindex("uuid")))) { viewholder.devicename.settext(c.getstring(c.getcolumnindex("devicename"))); sname= c.getstring(c.getcolumnindex("devicename")); } else { mbluetoothadapter.setname("noname"); } } while (c.movetonext()); } } } db.close(); } else viewholder.devicename.settext(r.string.unknown_device); viewholder.deviceaddress.settext(device.getaddress()); return view; } }
*from class calls following class , in added setting option.from above code should item selected name , uuid of device.*in should item details selected.
mdevicename = intent.getstringextra(extras_device_name); mdeviceaddress = intent.getstringextra(extras_device_address); mdeviceuuid=intent.getstringextra(extras_device_uuid); log.v("!!!!!!!!!!!!!!!!!!!!!!!!!!!!", "__________________________________________"+mdeviceuuid);
case r.id.menu_settings:
log.v("_______mdevicename______", ""+mdevicename); log.v("_______device uuid______", ""+mdeviceuuid); intent intent = new intent(this, editpreview.class); intent.putextra("dname", mdevicename); intent.putextra("daddress", mdeviceuuid); startactivityforresult(intent,0); return true;
and following edit class in adds database , when click on edittext giving device name of fistrow not item selected name.and after movig fist activity name in list shows same name.
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.edit_layout); edittext=(edittext)findviewbyid(r.id.device_text); db = new databaseadapter(this); intent = getintent(); if(i.hasextra("dname")) val = i.getstringextra("dname"); edittext.settext(val); if(i.hasextra("daddress")) pos=i.getstringextra("daddress"); db.open(); db.insertdata(pos,val,"off","off"); c = db.getdata(); if (c.movetofirst()) { { } while (c.movetonext()); } db.close(); } @override public void onbackpressed(){ db.open(); c=db.getdata(); if (c.movetofirst()) { { string strsql = "update devicedetails set devicename ='"+ edittext.gettext().tostring() +"' uuid = '"+c.getstring(c.getcolumnindex("uuid"))+"'" ; db.select(strsql); db.updatedata(pos, edittext.gettext().tostring()); intent intent=new intent(); intent.putextra("dname", edittext.gettext().tostring()); intent.putextra("daddress",pos); setresult(result_ok, intent); finish(); } while (c.movetonext()); } db.close(); super.onbackpressed(); }
Comments
Post a Comment