所以,我在学校有这个任务,我必须在Android Studio中创建一个管理日常任务的应用程序,基本上是日历,但活动保存在具有JSON格式的服务器中。问题是我在RecyclerView中有一天所有活动的列表,我必须为每个活动都有一个按钮,允许我从服务器上删除它,我不知道我怎么能这样做,我的意思是,当我删除一个活动时,我必须用它的ID来做 我目前有一个应用程序,但我必须添加该功能,我有一个活动,有一个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);
}
}