This is my code of a sample details gathering page,where once the customer enters his details, it will be stored until another reinstall of this application, there is no error in the code and it executes correctly, but the customer is able to move to the next activity without filling out the form
and i tried a bit of condition checks but all those failed, need some help in code logic
package asr.customer;
import java.io.File;
import java.util.Locale;
import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.content.ContentValues;
import android.text.Editable;
import android.database.sqlite.SQLiteDatabase;
import android.view.*;
import android.widget.*;
public class ASRCustomerAppActivity extends Activity implements Button.OnClickListener{
/** Called when the activity is first created. */
Button btn;
ContentValues values= new ContentValues();
SQLiteDatabase db;
String first,last,state,city,g;
int day,month,year;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn=(Button)findViewById(R.id.save);
btn.setOnClickListener(this);
File dbtest =new File("/data/data/asr.customer/databases/customerdetail1.db");
if(dbtest.exists())
{
// what to do if it does exist
Intent intent=new Intent();
intent.setClass(this,mapActivity.class);
startActivity(intent);
finish();
}
else
{
db=openOrCreateDatabase("customerdetail1.db",SQLiteDatabase.CREATE_IF_NECESSARY,null);
db.setVersion(1);
db.setLocale(Locale.getDefault());
db.setLockingEnabled(true);
final String table_create="CREATE TABLE customer("+"firstname TEXT,"+"lastname TEXT,"+"day INTEGER,"+"gender TEXT,"+"month INTEGER,"+"year INTEGER,"+"city TEXT,"+"state TEXT);";
db.execSQL(table_create);
EditText i2=(EditText)findViewById(R.id.first);
first=i2.getText().toString();
EditText i3=(EditText) findViewById(R.id.last1);
last=i3.getText().toString();
DatePicker d=(DatePicker) findViewById(R.id.date);
day=d.getDayOfMonth();
month= d.getMonth()+1;
year=d.getYear();
RadioGroup rg= (RadioGroup) findViewById(R.id.radiogroup);
RadioButton r1= (RadioButton) findViewById(R.id.radioButton1);
RadioButton r2= (RadioButton) findViewById(R.id.radioButton2);
if(r1.isChecked()==true)
{
g=r1.getText().toString();
}
else
{
g= r2.getText().toString();
}
EditText i4=(EditText) findViewById(R.id.city);
city=i4.getText().toString();
EditText i5=(EditText) findViewById(R.id.state);
state=i5.getText().toString();
}
}
public void onClick(View v) {
// what to do if it doesn't exist
do{
// code
Toast.makeText(ASRCustomerAppActivity.this, "Please Fill The Blank Spaces", Toast.LENGTH_LONG).show();
}while((first.equalsIgnoreCase("") || last.equalsIgnoreCase("") || city.equalsIgnoreCase("") || state.equalsIgnoreCase("")));
values.put("firstname",first);
values.put("lastname",last);
values.put("day",day);
values.put("month",month);
values.put("year",year);
values.put("gender",g);
values.put("city",city);
values.put("state",state);
db.insert("customer", null, values);
Intent intent=new Intent();
intent.setClass(this,mapActivity.class);
startActivity(intent);
finish();
}
}
instead of this
try this
and put this inside your onClick