android 日程提醒代码和布局文件
时间: 2023-09-22 16:07:58 浏览: 35
以下是一个简单的Android日程提醒应用的代码示例和布局文件:
布局文件:activity_main.xml
```xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/title_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:paddingTop="16dp"
android:text="My Schedule"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<ListView
android:id="@+id/schedule_listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/title_textView"
android:divider="@null"
android:dividerHeight="0dp" />
<Button
android:id="@+id/add_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:text="Add" />
</RelativeLayout>
```
Java 代码:MainActivity.java
```java
public class MainActivity extends AppCompatActivity {
private ListView scheduleListView;
private ScheduleListAdapter scheduleListAdapter;
private List<Schedule> scheduleList;
private Button addButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scheduleListView = findViewById(R.id.schedule_listView);
scheduleList = new ArrayList<>();
scheduleListAdapter = new ScheduleListAdapter(this, scheduleList);
scheduleListView.setAdapter(scheduleListAdapter);
addButton = findViewById(R.id.add_button);
addButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 添加新的日程
// ...
}
});
}
}
```
另外,你需要自定义一个适配器类 ScheduleListAdapter 来设置 ListView 中每一个日程的显示效果。