4.9
学生部分功能
• 所花时间:3
• 代码行数:391
• 博客容量:1
• 代码如下:
package com.example.undertaking;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Application;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.example.undertaking.TaskPackage.WeekDAO;
import com.example.undertaking.TaskPackage.WeekTask;
import com.example.undertaking.TaskPackage.WeekTaskDAO;
import com.example.undertaking.userDB.User;
import com.example.undertaking.userDB.UserDbUtil;
import com.example.undertaking.util.DateUtil;
import com.example.undertaking.util.ToastUtil;
public class setTaskOfWeek extends AppCompatActivity implements View.OnClickListener {
private TextView tv_name;
private EditText goal;
private WeekTask weekTask;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_set_task_of_week);
tv_name = findViewById(R.id.tv_name);
tv_name.setText("HELLO! "+MyApplication.user.name);
Button button=findViewById(R.id.bt_submit);
TextView textView=findViewById(R.id.tips);
goal = findViewById(R.id.et_goal);
weekTask=new WeekTask();
if(DateUtil.getDayOfWeek()!=1){
button.setEnabled(false);
textView.setText("只有周一可以填本周计划,下周再来吧!");
}else {
WeekDAO.WeekDaoRowListener weekDaoRowListener=new WeekDAO.WeekDaoRowListener() {
@Override
public void OperationCompletely(int result) {
weekTask.week_id=String.valueOf(result+1);
}
};
WeekDAO.getRowCount(MyApplication.user.id,weekDaoRowListener);
weekTask.stuID=MyApplication.user.id;
weekTask.finishRate="0";
button.setOnClickListener(this);
}
}
@Override
public void onClick(View v) {
weekTask.goal=goal.getText().toString();
WeekDAO.WeekDaoInsertListener listener=new WeekDAO.WeekDaoInsertListener() {
@Override
public void OperationCompletely(boolean result) {
if(result){
ToastUtil.show(setTaskOfWeek.this,"添加成功!");
}else {
ToastUtil.show(setTaskOfWeek.this,"添加失败!");
}
}
};
System.out.println(weekTask.goal);
WeekDAO.insert(weekTask,listener);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/mainBackground">
<TextView
android:id="@+id/tv_name"
android:layout_marginTop="10dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello!!"
android:textSize="30sp"
android:textColor="@color/white"/>
<TextView
android:id="@+id/tips"
android:layout_marginTop="50dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="输入本周的学习计划!"
android:textSize="20sp"
android:textColor="@color/white"
android:gravity="center"
/>
<EditText
android:id="@+id/et_goal"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="@drawable/my_edit"
android:maxLength="150"
android:textColor="@color/white"
/>
<Button
android:id="@+id/bt_submit"
android:layout_marginTop="50dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/my_button"
android:text="提交"
android:textColor="@color/white"
android:textSize="20sp"
/>
</LinearLayout>
浙公网安备 33010602011771号