Java 我的日历应用程序项目存在问题
所以,我在学校有一个作业,我必须在Android Studio中制作一个管理日常任务的应用程序,基本上是一个日历,但活动保存在一个JSON格式的服务器中。问题是我在RecyclerView中有一个一天中所有活动的列表,我必须为每个活动设置一个按钮,允许我从服务器上删除它,我不知道如何才能做到这一点,我的意思是,当我删除一个活动时,我必须使用它的ID来执行它。Java 我的日历应用程序项目存在问题,java,android,Java,Android,所以,我在学校有一个作业,我必须在Android Studio中制作一个管理日常任务的应用程序,基本上是一个日历,但活动保存在一个JSON格式的服务器中。问题是我在RecyclerView中有一个一天中所有活动的列表,我必须为每个活动设置一个按钮,允许我从服务器上删除它,我不知道如何才能做到这一点,我的意思是,当我删除一个活动时,我必须使用它的ID来执行它。 我目前有一个可以运行的应用程序,但我必须添加该功能,我有一个活动,它有一个recyclerView,并显示任务名称、开始和完成时间以及一个
我目前有一个可以运行的应用程序,但我必须添加该功能,我有一个活动,它有一个recyclerView,并显示任务名称、开始和完成时间以及一个按钮。我不知道我是否可以将任务ID放在一个隐藏字段中以便使用,或者是否有更好的方法来执行此操作。
我是Android编程新手,所以有点困惑 这是我用来获取JSON数据的代码
public class dayActivities extends AppCompatActivity {
private RecyclerView mRecyclerView;
private JsonManager json;
ArrayList<Tarea> list;
RequestQueue requestQueue;
String url="http://186.16.12.200:3000/agenda1";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_day_activities);
Bundle b = getIntent().getExtras();
String date = b.getString("fecha");
setTitle(getDate(date));
requestQueue= Volley.newRequestQueue(getApplicationContext());;
mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
mRecyclerView.setHasFixedSize(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(layoutManager);
this.getData(date);
}
public void getData(String date){
list=new ArrayList<Tarea>();
JsonArrayRequest arrReq = new JsonArrayRequest(Request.Method.GET, url + "?fecha=" + date,null,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
if (response.length() > 0) {
// The user does have repos, so let's loop through them all.
for (int i = 0; i < response.length(); i++) {
try {
// For each repo, add a new line to our repo list.
JSONObject jsonObj = response.getJSONObject(i);
Integer id = (Integer) jsonObj.get("id");
String actividad = jsonObj.get("actividad").toString();
String fecha = jsonObj.get("fecha").toString();
String inicio = jsonObj.get("horaInicio").toString();
String fin = jsonObj.get("horaFin").toString();
list.add(new Tarea(id,actividad,fecha,inicio,fin));
} catch (JSONException e) {
// If there is an error then output this to the logs.
Log.e("Volley", "Invalid JSON Object.");
}
}
mRecyclerView.setAdapter(new Adaptador(list));
} else {
// The user didn't have any repos.
Log.e("Volley", "Not found");
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("Volley", error.toString());
error.printStackTrace();
}
});
// Add the request we just defined to our request queue.
// The request queue will automatically handle the request as soon as it can.
requestQueue.add(arrReq);
}
public String getDate(String fecha){
String meses[]={"Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto,","Septiembre","Octubre","Noviembre","Diciembre"};
return fecha.substring(6)+" de "+meses[Integer.parseInt(fecha.substring(4,6))-1]+" del "+fecha.substring(0,4);
}
}
公共类dayActivities扩展了AppCompatActivity{
私人回收视图mRecyclerView;
私有JsonManager json;
数组列表;
请求队列请求队列;
字符串url=”http://186.16.12.200:3000/agenda1";
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u day\u activities);
Bundle b=getIntent().getExtras();
字符串日期=b.getString(“fecha”);
setTitle(getDate(date));
requestQueue=Volley.newRequestQueue(getApplicationContext());;
mRecyclerView=(RecyclerView)findViewById(R.id.my\u recycler\u视图);
mRecyclerView.setHasFixedSize(true);
LinearLayoutManager布局管理器=新的LinearLayoutManager(getApplicationContext());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(layoutManager);
此.getData(日期);
}
public void getData(字符串日期){
列表=新的ArrayList();
JsonArrayRequest ARREQ=新的JsonArrayRequest(Request.Method.GET,url+“?fecha=“+date,null,
新的Response.Listener(){
@凌驾
公共void onResponse(JSONArray响应){
if(response.length()>0){
//用户确实有回购协议,所以让我们遍历它们。
对于(int i=0;i
您似乎走对了方向。您可以创建一个与Android客户端对话的RestAPI。如果您不需要身份验证,这并不十分困难。如果您提供一些代码作为起点,我们可以为您提供更多帮助。我已经有了生成Json请求的部分,我使用了Volley。我编辑了我的帖子,添加了用于获取数据并将其放入recyclerview的代码。问题是,当我按下recyclerview上的delete按钮时,会发出活动的delete请求