gpt4 book ai didi

java - Android-java 条件检查错误 - 需要纠正一些代码逻辑

转载 作者:行者123 更新时间:2023-12-02 07:55:41 26 4
gpt4 key购买 nike

这是我的示例详细信息收集页面的代码,一旦客户输入了他的详细信息,它将被存储,直到再次重新安装该应用程序,代码中没有错误并且执行正确,但客户能够无需填写表格即可进入下一个 Activity

我尝试了一些条件检查,但所有这些都失败了,需要代码逻辑方面的一些帮助

    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();
}



}

最佳答案

而不是这个

while((first.equalsIgnoreCase("") || last.equalsIgnoreCase("") || city.equalsIgnoreCase("") || state.equalsIgnoreCase("")));

试试这个

while((first.length==0|| last.length==0 || city.length==0|| state.length==0));

并将其放入您的 onClick

 first=i2.getText().toString();
last=i3.getText().toString();
city=i4.getText().toString();
state=i5.getText().toString();

关于java - Android-java 条件检查错误 - 需要纠正一些代码逻辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9683100/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com