我在xml中有6个EditText字段..在按钮上单击我需要验证是否所有EditText都有值或者它是空的.目前我逐个检查每个EditText ..如何一次检查所有.
代码
private Button BtnSave;
EditText ev_last_name,ev_first_name,ev_email,ev_password,ev_confirm_password,ev_phone;
String last_name,first_name,email,password,confirm_password,phone;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.signup);
BtnSave=(Button) findViewById(R.id.BtnSave);
ev_last_name=(EditText)findViewById(R.id.edit_lname);
ev_first_name=(EditText)findViewById(R.id.edit_fname);
ev_email=(EditText)findViewById(R.id.edit_email);
ev_password=(EditText)findViewById(R.id.edit_passwd);
ev_confirm_password=(EditText)findViewById(R.id.edit_cpasswd);
ev_phone=(EditText)findViewById(R.id.edit_phone);
BtnSave.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
last_name=ev_last_name.getText().toString();
first_name=ev_first_name.getText().toString();
email=ev_email.getText().toString();
password=ev_password.getText().toString();
confirm_password=ev_confirm_password.getText().toString();
phone=ev_phone.getText().toString();
if ((ev_last_name.getText().toString().length() <= 0))
{
System.out.println(" The EditText is empty");
//I will use the toast later
}
}
});
}
Run Code Online (Sandbox Code Playgroud) 嗨,我正在尝试开发一个自定义锁定屏幕,我想在其中替换幻灯片以使用ImageView解锁,如图所示.

这是我到目前为止所尝试的.
我在屏幕的左下角放置了一个Image,并使用onTouchListner在下面拖动Image水平代码.
left_Locker.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
int eid = event.getAction();
switch (eid) {
case MotionEvent.ACTION_DOWN:
toastText.setVisibility(View.VISIBLE);
toastText.setTextColor(Color.BLACK);
toastText.setText("Slide to Unlock");
break;
case MotionEvent.ACTION_MOVE:
RelativeLayout.LayoutParams mParams = (RelativeLayout.LayoutParams) left_Locker.getLayoutParams();
int x = (int) event.getRawX();
mParams.leftMargin = x - 50;
left_Locker.setLayoutParams(mParams);
break;
case MotionEvent.ACTION_UP:
toastText.setVisibility(View.GONE);
break;
default:
break;
}
return true;
}
});
Run Code Online (Sandbox Code Playgroud)
图像确实水平移动,但我正在寻找的是如图所示也可以拖动图像背景.我使用ImageView走在正确的轨道上吗?
下面是我尝试过的Image.

我可以水平移动图像但是如何在滚动时获取背景?
我正在尝试以编程方式从手机中选择可用的联系人,我正在使用以下代码
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
startActivityForResult(intent, 1);
Run Code Online (Sandbox Code Playgroud)
但问题是如何使用联系人页面中的复选框一次选择多个联系人?
嗨,我正在尝试使用预准备语句将数据插入数据库,但我得到语法错误,请你帮忙
public boolean SignUp(String last_name, String first_name,String email, String password,String confirm_password,String phone){
Connect connect = new Connect();
Connection conn = connect.Connection();
java.sql.PreparedStatement preparedStatement = null;
//NULL is the column for auto increment
String insertQuery = "INSERT INTO users VALUES (NULL, ?, ?, ?, ?, ?, ?)";
preparedStatement = conn.prepareStatement(insertQuery);
preparedStatement.setString(1, last_name);
preparedStatement.setString(2, first_name);
preparedStatement.setString(3, email);
preparedStatement.setString(4, password);
preparedStatement.setString(5, confirm_password);
preparedStatement.setString(6, phone);
int rs = preparedStatement.executeUpdate(insertQuery);
conn.close();
Run Code Online (Sandbox Code Playgroud)
}
这是错误消息
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual …Run Code Online (Sandbox Code Playgroud) 我正在使用foll0wing代码插入数据库,它工作正常,因为我可以看到数据填充在db中,但是我想以编程方式捕获结果,无论是成功还是失败
1)这是要插入的代码
public void SignUp(String last_name, String first_name, String email,
String password, String confirm_password, String phone) {
Connect connect = new Connect();
Connection conn = connect.Connection();
Statement stmt = conn.createStatement();
String query = "INSERT INTO users VALUES(NULL,('" + last_name + "'),('"
+ first_name + "'),('" + email + "'),('" + password + "'),('"
+ confirm_password + "'),('" + phone + "'))";
stmt.executeUpdate(query);
conn.close();
}
Run Code Online (Sandbox Code Playgroud)
2)这是我用来连接的代码
public Connection Connection() {
Connection conn = null;
try {
String userName = "admin";
String …Run Code Online (Sandbox Code Playgroud) 在java.How将sql查询的结果保存到变量中?
java.sql.PreparedStatement preparedStatement = null;
String query = "select season from seasonTable where league_name=?";
preparedStatement = conn.prepareStatement(query);
preparedStatement.setString(1, league);
ResultSet rs = preparedStatement.executeQuery();
Run Code Online (Sandbox Code Playgroud)
我需要将检索到的季节保存到变量中,我该怎么做?
我正在使用搜索栏。我只想通过移动拇指来控制它。
如何禁用对 ProgressDrawable 的点击?
我尝试过android:clickable="false",但没有成功。
我在 XML 中寻找条形码
<SeekBar
android:id="@+id/myseek"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:maxHeight="500dp"
android:minHeight="50dp"
android:paddingBottom="30dp"
android:progressDrawable="@drawable/progress_left"
android:thumb="@drawable/left_unlocker_bkg" >
</SeekBar>
Run Code Online (Sandbox Code Playgroud)
我的 onSeekChangedListner 的 Seekbar 代码
unlockSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
toastText.setVisibility(View.GONE);
seekBar.setProgress(0);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
if (seekBar.getProgress() < 10) {
seekBar.setProgress(0);
}
toastText.setVisibility(View.VISIBLE);
toastText.setText("Slide to Unclock");
}
@Override
public void onProgressChanged(SeekBar seekBar,
int progress, boolean fromUser) {
if (progress == 100) {
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(100);
finish(); …Run Code Online (Sandbox Code Playgroud)