android - how to get data from another activity to a spinner? -



android - how to get data from another activity to a spinner? -

please help me info manageclass contain editextclassno. managestudents contain spinnerclassno. give thanks in advanced

manageclass

package com.e_attendance; import android.app.activity; import android.app.alertdialog.builder; import android.content.context; import android.database.cursor; import android.database.sqlite.sqlitedatabase; import android.os.bundle; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.edittext; public class manageclass extends activity implements onclicklistener { edittext editclassno; button btnadd, btndelete, btnmodify, btnviewall; sqlitedatabase db; public static final string prefs_class = "mypreferencesfile"; @override public void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.classdetail); editclassno = (edittext) findviewbyid(r.id.editclassno); btnadd = (button) findviewbyid(r.id.btnadd); btndelete = (button) findviewbyid(r.id.btndelete); btnmodify = (button) findviewbyid(r.id.btnmodify); btnviewall = (button) findviewbyid(r.id.btnviewall); btnadd.setonclicklistener(this); btndelete.setonclicklistener(this); btnmodify.setonclicklistener(this); btnviewall.setonclicklistener(this); db = openorcreatedatabase("classdb", context.mode_private, null); db.execsql("create table if not exists class (classno varchar);"); } @override public void onclick(view view) { if (view == btnadd) { if (editclassno.gettext().tostring().trim().length() == 0) { showmessage("error", "enter class no please"); return; } db.execsql("insert class values('" + editclassno.gettext() + "');"); showmessage("success", "record added"); cleartext(); } if (view == btndelete) { if (editclassno.gettext().tostring().trim().length() == 0) { showmessage("error", "please come in classno"); return; } cursor c = db.rawquery("select * class classno='" + editclassno.gettext() + "'", null); if (c.movetofirst()) { db.execsql("delete class classno='" + editclassno.gettext() + "'"); showmessage("success", "record deleted"); } else { showmessage("error", "invalid classno"); } cleartext(); } if (view == btnmodify) { if (editclassno.gettext().tostring().trim().length() == 0) { showmessage("error", "please come in classno"); return; } cursor c = db.rawquery("select * class classno='" + editclassno.gettext() + "'", null); if (c.movetofirst()) { db.execsql("update class set class classno='" + editclassno.gettext() + "'"); showmessage("success", "record modified"); } else { showmessage("error", "invalid clasno"); } cleartext(); } if (view == btnviewall) { cursor c = db.rawquery("select * class", null); if (c.getcount() == 0) { showmessage("error", "no records found"); return; } stringbuffer buffer = new stringbuffer(); while (c.movetonext()) { buffer.append("classno: " + c.getstring(0) + "\n"); ; } showmessage("classes no.", buffer.tostring()); } } public void cleartext() { editclassno.settext(""); editclassno.requestfocus(); } public void showmessage(string title, string message) { builder builder = new builder(this); builder.setcancelable(true); builder.settitle(title); builder.setmessage(message); builder.show(); } }

managestudents

package com.e_attendance; import android.app.activity; import android.app.alertdialog.builder; import android.content.context; import android.database.cursor; import android.database.sqlite.sqlitedatabase; import android.os.bundle; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.edittext; import android.widget.spinner; public class managestudents extends activity implements onclicklistener { edittext editrollno, editname, editemail; button btnadd, btndelete, btnmodify, btnview, btnviewall, btnshowinfo; sqlitedatabase db; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.studentdetails); editrollno = (edittext) findviewbyid(r.id.editrollno); editname = (edittext) findviewbyid(r.id.editname); editemail = (edittext) findviewbyid(r.id.editemail); btnadd = (button) findviewbyid(r.id.btnadd); btndelete = (button) findviewbyid(r.id.btndelete); btnmodify = (button) findviewbyid(r.id.btnmodify); btnview = (button) findviewbyid(r.id.btnview); btnviewall = (button) findviewbyid(r.id.btnviewall); btnadd.setonclicklistener(this); btndelete.setonclicklistener(this); btnmodify.setonclicklistener(this); btnview.setonclicklistener(this); btnviewall.setonclicklistener(this); db = openorcreatedatabase("studentdb", context.mode_private, null); db.execsql("create table if not exists student(rollno varchar,name varchar,email varchar);"); } public void onclick(view view) { if (view == btnadd) { if (editrollno.gettext().tostring().trim().length() == 0 || editname.gettext().tostring().trim().length() == 0 || editemail.gettext().tostring().trim().length() == 0) { showmessage("error", "please come in values"); return; } db.execsql("insert pupil values('" + editrollno.gettext() + "','" + editname.gettext() + "','" + editemail.gettext() + "');"); showmessage("success", "record added"); cleartext(); } if (view == btndelete) { if (editrollno.gettext().tostring().trim().length() == 0) { showmessage("error", "please come in rollno"); return; } cursor c = db.rawquery("select * pupil rollno='" + editrollno.gettext() + "'", null); if (c.movetofirst()) { db.execsql("delete pupil rollno='" + editrollno.gettext() + "'"); showmessage("success", "record deleted"); } else { showmessage("error", "invalid rollno"); } cleartext(); } if (view == btnmodify) { if (editrollno.gettext().tostring().trim().length() == 0) { showmessage("error", "please come in rollno"); return; } cursor c = db.rawquery("select * pupil rollno='" + editrollno.gettext() + "'", null); if (c.movetofirst()) { db.execsql("update pupil set name='" + editname.gettext() + "',email='" + editemail.gettext() + "' rollno='" + editrollno.gettext() + "'"); showmessage("success", "record modified"); } else { showmessage("error", "invalid rollno"); } cleartext(); } if (view == btnview) { if (editrollno.gettext().tostring().trim().length() == 0) { showmessage("error", "please come in rollno"); return; } cursor c = db.rawquery("select * pupil rollno='" + editrollno.gettext() + "'", null); if (c.movetofirst()) { editname.settext(c.getstring(1)); editemail.settext(c.getstring(2)); } else { showmessage("error", "invalid rollno"); cleartext(); } } if (view == btnviewall) { cursor c = db.rawquery("select * student", null); if (c.getcount() == 0) { showmessage("error", "no records found"); return; } stringbuffer buffer = new stringbuffer(); while (c.movetonext()) { buffer.append("rollno: " + c.getstring(0) + "\n"); buffer.append("name: " + c.getstring(1) + "\n"); buffer.append("email: " + c.getstring(2) + "\n\n"); } showmessage("student details", buffer.tostring()); } } public void showmessage(string title, string message) { builder builder = new builder(this); builder.setcancelable(true); builder.settitle(title); builder.setmessage(message); builder.show(); } public void cleartext() { editrollno.settext(""); editname.settext(""); editemail.settext(""); editrollno.requestfocus(); } }

classdetail -xml

<?xml version="1.0" encoding="utf-8"?> <absolutelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mylayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchcolumns="0" > <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="110dp" android:layout_y="10dp" android:text="@string/title" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="30dp" android:layout_y="50dp" android:text="@string/roll_no" /> <button android:id="@+id/btnviewall" android:layout_width="100dp" android:layout_height="40dp" android:layout_x="31dp" android:layout_y="362dp" android:text="@string/view_all" /> <button android:id="@+id/btnmodify" android:layout_width="100dp" android:layout_height="40dp" android:layout_x="33dp" android:layout_y="310dp" android:text="@string/modify" /> <button android:id="@+id/btnview" android:layout_width="100dp" android:layout_height="40dp" android:layout_x="143dp" android:layout_y="359dp" android:text="@string/view" /> <button android:id="@+id/btndelete" android:layout_width="100dp" android:layout_height="40dp" android:layout_x="145dp" android:layout_y="310dp" android:text="@string/delete" /> <button android:id="@+id/btnadd" android:layout_width="100dp" android:layout_height="40dp" android:layout_x="85dp" android:layout_y="264dp" android:text="@string/add" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="31dp" android:layout_y="104dp" android:text="@string/name" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="28dp" android:layout_y="208dp" android:text="enter classno" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="33dp" android:layout_y="149dp" android:text="@string/email" /> <edittext android:id="@+id/editemail" android:layout_width="150dp" android:layout_height="40dp" android:layout_x="141dp" android:layout_y="138dp" android:ems="10" android:inputtype="textemailaddress" /> <edittext android:id="@+id/editname" android:layout_width="150dp" android:layout_height="40dp" android:layout_x="140dp" android:layout_y="86dp" android:ems="10" android:inputtype="text" /> <edittext android:id="@+id/editrollno" android:layout_width="150dp" android:layout_height="40dp" android:layout_x="142dp" android:layout_y="35dp" android:ems="10" android:inputtype="number" /> <spinner android:id="@+id/spinnerclassno" android:layout_width="132dp" android:layout_height="38dp" android:layout_x="139dp" android:layout_y="201dp" /> </absolutelayout>

studentsdetails- xml

<?xml version="1.0" encoding="utf-8"?> <absolutelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mylayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchcolumns="0" > <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="110dp" android:layout_y="10dp" android:text="@string/title" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="30dp" android:layout_y="50dp" android:text="@string/roll_no" /> <button android:id="@+id/btnviewall" android:layout_width="100dp" android:layout_height="40dp" android:layout_x="31dp" android:layout_y="362dp" android:text="@string/view_all" /> <button android:id="@+id/btnmodify" android:layout_width="100dp" android:layout_height="40dp" android:layout_x="33dp" android:layout_y="310dp" android:text="@string/modify" /> <button android:id="@+id/btnview" android:layout_width="100dp" android:layout_height="40dp" android:layout_x="143dp" android:layout_y="359dp" android:text="@string/view" /> <button android:id="@+id/btndelete" android:layout_width="100dp" android:layout_height="40dp" android:layout_x="145dp" android:layout_y="310dp" android:text="@string/delete" /> <button android:id="@+id/btnadd" android:layout_width="100dp" android:layout_height="40dp" android:layout_x="85dp" android:layout_y="264dp" android:text="@string/add" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="31dp" android:layout_y="104dp" android:text="@string/name" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="28dp" android:layout_y="208dp" android:text="enter classno" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="33dp" android:layout_y="149dp" android:text="@string/email" /> <edittext android:id="@+id/editemail" android:layout_width="150dp" android:layout_height="40dp" android:layout_x="141dp" android:layout_y="138dp" android:ems="10" android:inputtype="textemailaddress" /> <edittext android:id="@+id/editname" android:layout_width="150dp" android:layout_height="40dp" android:layout_x="140dp" android:layout_y="86dp" android:ems="10" android:inputtype="text" /> <edittext android:id="@+id/editrollno" android:layout_width="150dp" android:layout_height="40dp" android:layout_x="142dp" android:layout_y="35dp" android:ems="10" android:inputtype="number" /> <spinner android:id="@+id/spinnerclassno" android:layout_width="132dp" android:layout_height="38dp" android:layout_x="139dp" android:layout_y="201dp" /> </absolutelayout>

for have create info class markup interface(serialization) illustration

public class transferdata implements serializable { private string block; private string addressstring; public string getaddressstring() { homecoming addressstring; } public void setaddressstring(string addressstring) { this.addressstring = addressstring; } public string getblock() { homecoming block; } public void setblock(string block) { this.block = block; } } put info object.

//to pass :

transferdata obj = new transferdata(); obj.setblock("abc"); obj.setaddressstring("abc"); intent.putextra("myclass", obj); get object in activity.

// retrieve object in sec activity

transferdata obj = getintent().getserializableextra("myclass"); system.out.println(""+obj.getblock());

android eclipse sharedpreferences android-spinner

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -