Hi friends I am trying all the possible solutions but i didnt get any prper solution. My project is attendance based. When i select the checkbox to mark attendance of students, On button click it will save on my sqlite database. but here only save one value that is last value on spinner. plz any one help its really urgent for me. How can i store multiple checkbox value of spinner into database on button click with other values. Plz its really urgent. My code below please go through it. Plz suggest me.
This is My attendancetakerclass
attendancetakerclass
public class AttendanceTracker extends Activity {
// ArrayList<String> NameList;
DataBaseHelper dbHelper;
String classcode;
SQLiteDatabase db;
Button save_attendance;
String type2="student";
//String type1="student";
//RadioGroup rg;
TextView date,time;
static String class1;
String type;
String slot;
String datetime1;
String subject, bioid,datevalue,timevalue;
List<Model> bioid1;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.attendancetaker);
dbHelper=new DataBaseHelper(AttendanceTracker.this);
this.db=dbHelper.getReadableDatabase();
date=(TextView)findViewById(R.id.tvdatetime);
datevalue=date.getText().toString();
time=(TextView)findViewById(R.id.tvtime);
timevalue=time.getText().toString();
String currentDateTimeString = DateFormat.getDateInstance().format(new Date());
// textView is the TextView view that should display it
date.setText(currentDateTimeString);
Time today = new Time(Time.getCurrentTimezone());
today.setToNow();
time.setText(today.format("%k:%M:%S"));
//bioid=dbHelper.getbioid();
Bundle extras = this.getIntent().getExtras();
String inputfname1=extras.getString("firstn1");
String inputlname1=extras.getString("lastn1");
String inputclass=extras.getString("class");
String inputsub=extras.getString("sub");
String inputslot=extras.getString("type");
String inputprctslot=extras.getString("slot");
TextView viewfname = (TextView) findViewById(R.id.tvname);
viewfname.setText(inputfname1);
TextView viewlname = (TextView) findViewById(R.id.tvsurnamevalue);
viewlname.setText(inputlname1);
TextView viewclass = (TextView) findViewById(R.id.tvclassvalue);
viewclass.setText(inputclass);
classcode = viewclass.getText().toString();
TextView viewsub = (TextView) findViewById(R.id.tvsubjectname);
viewsub.setText(inputsub);
subject = viewsub.getText().toString();
TextView viewslot = (TextView) findViewById(R.id.tvslotvalue);
viewslot.setText(inputslot);
type = viewslot.getText().toString();
TextView viewprcts = (TextView) findViewById(R.id.tvprctsvalue);
viewprcts.setText(inputprctslot);
slot = viewprcts.getText().toString();
ListView studentList=(ListView)findViewById(R.id.take_attend_list);
bioid1=this.getbioid();
ArrayAdapter<Model> adapter = new MyAdapter(this,getdata(),getdatalname(),getbioid());
studentList.setAdapter(adapter);
}
public List<Model> getdata()
{
List<Model> list = new ArrayList<Model>();
Cursor cursor =db.rawQuery("SELECT firstname FROM users WHERE type='"+type2+"' AND class_code='"+classcode+"'", null);
//Cursor cursor = db.rawQuery("SELECT firstname,lastname FROM attndrecords", null);
if(cursor.moveToFirst())
{
do
{
list.add(get(cursor.getString(cursor.getColumnIndex("firstname"))));
//list.add(get(cursor.getString(cursor.getColumnIndex("lastname"))));
// bioid= cursor.getString(cursor.getColumnIndex("bioid"));
//list.add(get(cursor.getString(cursor.getColumnIndex("bioid"))));
}while(cursor.moveToNext());
}
return list;
}
public List<Model> getbioid()
{
List<Model> list = new ArrayList<Model>();
Cursor cursor =db.rawQuery("SELECT bioid FROM users WHERE type='"+type2+"' AND class_code='"+classcode+"'", null);
//Cursor cursor = db.rawQuery("SELECT firstname,lastname FROM attndrecords", null);
if(cursor.moveToFirst())
{
do
{
//list.add(get(cursor.getString(cursor.getColumnIndex("firstname"))));
//list.add(get(cursor.getString(cursor.getColumnIndex("lastname"))));
// bioid= cursor.getString(cursor.getColumnIndex("bioid"));
list.add(get(cursor.getString(cursor.getColumnIndex("bioid"))));
}while(cursor.moveToNext());
}
return list;
}
private Model get(String string) {
// TODO Auto-generated method stub
return new Model(string, string, string);
}
public List<Model> getdatalname()
{
List<Model> listlname = new ArrayList<Model>();
Cursor cursor =db.rawQuery("SELECT lastname FROM users WHERE type='"+type2+"' AND class_code='"+classcode+"'", null);
//Cursor cursor = db.rawQuery("SELECT firstname,lastname FROM attndrecords", null);
if(cursor.moveToFirst())
{
do
{
//list.add(cursor.getString(cursor.getColumnIndex("firstname")));
listlname.add(get(cursor.getString(cursor.getColumnIndex("lastname"))));
}while(cursor.moveToNext());
}
return listlname;
}
/*public String getbioid()
{
String query = "SELECT bioid FROM users WHERE type='" +type2+"' AND class_code='"+classcode+"'";
Cursor cursor=db.rawQuery(query, null);
if(cursor.getCount()<0) // UserName Not Exist
{
cursor.close();
return "NOT EXIST";
}
cursor.moveToFirst();
String bioid= cursor.getString(cursor.getColumnIndex("bioid"));
cursor.close();
return bioid;
}*/
public void insertdata()
{
StringBuffer sb = new StringBuffer();
// Retrive Data from list
for (Model bean : bioid1) {
if (bean.isSelected()) {
sb.append(bean.getBioid());
//sb.append(",");
Toast.makeText(this, sb.toString().trim(), 1000);
}
}
String query = "INSERT INTO '"+classcode+"'(bioid,date,time,subject,slot) VALUES('"+sb+"','"+datevalue+"','"+timevalue+"','"+subject+"','"+slot+"')";
Cursor cursor=db.rawQuery(query, null);
if(cursor.getCount()<0) // UserName Not Exist
{
cursor.close();
return;
}
cursor.moveToFirst();
cursor.close();
}
/*public void savedata(String bioid,String datevalue,String timevalue,String subject,String slot) {
// TODO Auto-generated method stub
ContentValues values = new ContentValues();
values.put("bioid", bioid);
values.put("date", datevalue);
values.put("time", timevalue);
values.put("subject", subject);
values.put("slot", slot);
db.insert(classcode, null, values);
db.close();
}*/
public void submit_details(View v)
{
//savedata(bioid, datevalue, timevalue, subject, slot);
insertdata();
Toast.makeText(AttendanceTracker.this, "Saved", Toast.LENGTH_LONG).show();
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setMessage("Attendance Submitted Successfully. Please Connect the Device to WiFi");
alertDialogBuilder.setPositiveButton("yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
Intent i = new Intent(AttendanceTracker.this, Attendance.class);
startActivity(i);
}
});
alertDialogBuilder.setNegativeButton("No",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish(); }
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
}
----------
----------
## My AttendancePOJO ##
<pre><code>package com.edbeans.attendance;
public class AttendancePOJO {
String bioid;
String date;
String time;
String subject;
String slot;
public AttendancePOJO()
{
}
public AttendancePOJO(String bioid, String date, String time,String subject, String slot)
{
this.bioid=bioid;
this.date=date;
this.time=time;
this.subject=subject;
this.slot=slot;
}
public String getBioid() {
return bioid;
}
public void setBioid(String bioid) {
this.bioid = bioid;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getSlot() {
return slot;
}
public void setSlot(String slot) {
this.slot = slot;
}
}
--------------------------------------------------------------------------------
## My custom adapter ##
<pre><code>package com.edbeans.attendance;
import java.util.List;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
public class MyAdapter extends ArrayAdapter<Model> {
private final List<Model> list;
private final List<Model> list2;
private final List<Model> list3;
private final Activity context;
public MyAdapter(Activity context, List<Model> list, List<Model> list2, List<Model> list3) {
super(context, R.layout.attend_layout, list);
this.context = context;
this.list = list;
this.list2=list2;
this.list3=list3;
}
static class ViewHolder {
protected TextView text;
protected CheckBox checkbox;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.attend_layout, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) view.findViewById(R.id.tvstudentfname);
viewHolder.checkbox = (CheckBox) view.findViewById(R.id.checkBox1);
viewHolder.checkbox
.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
Model element = (Model) viewHolder.checkbox
.getTag();
element.setSelected(buttonView.isChecked());
}
});
view.setTag(viewHolder);
viewHolder.checkbox.setTag(list.get(position));
} else {
view = convertView;
((ViewHolder) view.getTag()).checkbox.setTag(list.get(position));
}
ViewHolder holder = (ViewHolder) view.getTag();
holder.text.setText(list.get(position).getName()+ " " + list2.get(position).getLname()+" " + list3.get(position).getBioid());
// holder.text(list3.get(position));
holder.checkbox.setChecked(list.get(position).isSelected());
return view;
}
}
This is My code please how can i store all checked value means bioid of all students and date time class how can i store multiple values at a time on single button click...... please suggest me.. its really very urgent work i have deadline tomorrow evening... Please guys help me. thanks in advance.
Aucun commentaire:
Enregistrer un commentaire