Android studio 职工考勤系统代码
时间: 2023-08-05 07:02:18 浏览: 108
以下是一个简单的Android Studio职工考勤系统的代码示例,包括了登录界面、考勤打卡界面、考勤记录查询界面等基本功能。
XML布局文件:
登录界面:
```xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/username_hint"
android:inputType="text" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/password_hint"
android:inputType="textPassword" />
<Button
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/login_button" />
</LinearLayout>
```
考勤打卡界面:
```xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/greeting"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/greeting"
android:textSize="20sp"
android:layout_marginTop="100dp"
android:gravity="center" />
<Button
android:id="@+id/check_in_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/check_in_button"
android:layout_below="@id/greeting"
android:layout_marginTop="50dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="@color/colorPrimary"
android:textColor="@android:color/white" />
<Button
android:id="@+id/check_out_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/check_out_button"
android:layout_below="@id/check_in_button"
android:layout_marginTop="20dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="@color/colorPrimary"
android:textColor="@android:color/white" />
</RelativeLayout>
```
考勤记录查询界面:
```xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/title"
android:textSize="20sp"
android:gravity="center"
android:layout_marginTop="50dp"
android:layout_marginBottom="20dp" />
<ListView
android:id="@+id/attendance_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
```
Java代码:
登录界面:
```java
public class LoginActivity extends AppCompatActivity {
private EditText mUsernameEditText;
private EditText mPasswordEditText;
private Button mLoginButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mUsernameEditText = findViewById(R.id.username);
mPasswordEditText = findViewById(R.id.password);
mLoginButton = findViewById(R.id.login);
mLoginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String username = mUsernameEditText.getText().toString();
String password = mPasswordEditText.getText().toString();
if (TextUtils.isEmpty(username)) {
mUsernameEditText.setError(getString(R.string.username_error));
return;
}
if (TextUtils.isEmpty(password)) {
mPasswordEditText.setError(getString(R.string.password_error));
return;
}
// TODO: Add login logic here
}
});
}
}
```
考勤打卡界面:
```java
public class CheckInActivity extends AppCompatActivity {
private TextView mGreetingTextView;
private Button mCheckInButton;
private Button mCheckOutButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_check_in);
mGreetingTextView = findViewById(R.id.greeting);
mCheckInButton = findViewById(R.id.check_in_button);
mCheckOutButton = findViewById(R.id.check_out_button);
// TODO: Add greeting message based on current time
mCheckInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO: Add check-in logic here
}
});
mCheckOutButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO: Add check-out logic here
}
});
}
}
```
考勤记录查询界面:
```java
public class AttendanceActivity extends AppCompatActivity {
private TextView mTitleTextView;
private ListView mAttendanceListView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_attendance);
mTitleTextView = findViewById(R.id.title);
mAttendanceListView = findViewById(R.id.attendance_list);
// TODO: Load attendance records from database and display them in the list view
}
}
```
在上面的Java代码中,我们可以看到一些基本的逻辑,例如在登录界面中检查用户名和密码是否为空、在考勤打卡界面中根据当前时间显示不同的问候语、在考勤记录查询界面中加载考勤记录并显示在列表视图中。当然,这些代码只是一个简单的示例,实际的职工考勤系统可能需要更多的功能和逻辑。
希望这个简单的代码示例对您有所帮助!
阅读全文