这是我尝试制作的第一个应用程序,并且很难从头开始自学。我一直在学习如何在Android Studio中使用android.widget.CalendarView库来创建基本日历,但是我一直在努力弄清楚如何将事件添加到日期并将其存储在一个数据库。这是它的所有代码。到目前为止我有三节课:
1:主要
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button goToCalendarButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
goToCalendarButton = (Button) findViewById(R.id.goToCalendarButton);
goToCalendarButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, CalendarActivity.class);
//intent.putExtra();
startActivity(intent);
}
});
}
}
2:日历
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CalendarView;
import android.widget.Toast;
public class CalendarActivity extends AppCompatActivity {
CalendarView calendar;
Button selectDateButton;
Button goHomeButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calendar);
selectDateButton = (Button) findViewById(R.id.selectDateButton);
selectDateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(CalendarActivity.this, DateActivity.class);
//intent.putExtra();
startActivity(intent);
}
});
goHomeButton = (Button) findViewById(R.id.goHomeButton);
goHomeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(CalendarActivity.this, MainActivity.class);
//intent.putExtra();
startActivity(intent);
}
});
calendar = (CalendarView) findViewById(R.id.calendar1);
calendar.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(@NonNull CalendarView view, int year, int month, int dayOfMonth) {
Toast.makeText(getBaseContext(), "Selected date "+(month+1)+"/"+dayOfMonth+"/"+year,Toast.LENGTH_SHORT).show();
}
});
}
}
3:日期
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class DateActivity extends AppCompatActivity {
Button goHomeButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_date);
goHomeButton = (Button) findViewById(R.id.goHomeButton);
goHomeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(DateActivity.this, MainActivity.class);
//intent.putExtra();
startActivity(intent);
}
});
}
}
4:活动
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class EventActivity extends AppCompatActivity {
Button goHomeButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_event);
goHomeButton = (Button) findViewById(R.id.goHomeButton);
goHomeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Intent intent = new Intent(EventActivity.this, MainActivity.class);
//intent.putExtra();
startActivity(intent);
}
});
}
}
学习和理解所有内容非常困难,这是17年级作为我成绩的50%,所以任何帮助都非常感谢!