學習時間2h
程式碼量:100
package com.example.text_five;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.example.text_five.dao.UserDao;
import com.example.text_five.entity.User;
import java.sql.SQLException;
public class target extends AppCompatActivity {
EditText mubiao = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main7);
mubiao = findViewById(R.id.b2);
}
public void 目標2(View view) {
String mubiao1 = mubiao.getText().toString();
User user = new User();
user.setTarget(mubiao1);
Intent intent = getIntent();
String account = intent.getStringExtra("account");
new Thread() {
@Override
public void run() {
UserDao userDao = new UserDao();
boolean flag = userDao.tar(user, account);
runOnUiThread(new Runnable() {
@Override
public void run() {
if (flag) {
Toast.makeText(target.this, "設定目標成功", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(target.this, "設定目標失敗", Toast.LENGTH_SHORT).show();
}
}
});
}
}.start();
}
}