creating a text file and saving data in android -
i new programming android apps.
in following code, want take input user through number of edittexts , save them file. use android studio , after giving inputs, checked file , empty. try display contents , still no output. wrong code?
please me.
public class user extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_user); nextclick(); } public void nextclick() { final context context = this; button next =(button) findviewbyid(r.id.usernext); next.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { try { edittext e1 = (edittext) findviewbyid(r.id.name); edittext e2 = (edittext) findviewbyid(r.id.designation); edittext e3 = (edittext) findviewbyid(r.id.orgname); edittext e4 = (edittext) findviewbyid(r.id.address); edittext e5 = (edittext) findviewbyid(r.id.city); edittext e6 = (edittext) findviewbyid(r.id.state); edittext e7 = (edittext) findviewbyid(r.id.zip); fileoutputstream fos = openfileoutput("data.txt", context.mode_world_writeable); outputstreamwriter osw = new outputstreamwriter(fos); osw.write(e1.tostring()); fos.flush(); fos.close(); } catch(exception e) { } try { fileinputstream fis = new fileinputstream("data.txt"); while(fis.read()!=-1) { system.out.println((char)fis.read()); } } catch(exception e) { } intent intent3 = new intent(context,com.example.cheruvu.rs.user2.class); startactivity(intent3); } }); } }
you need gettext() edittext fields when writing file , shown below
osw.write(e1.gettext().tostring());
Comments
Post a Comment