Android restapi casha存储数据,但当我单击listview项时,我希望看到它们存储在cacha中的服务中的所有项
我应用缓存,但它只工作一次,当我点击第一个项目时,它会显示数据,然后当我点击另一个项目时,它会显示相同的数据。如何修复它 这是我的密码Android restapi casha存储数据,但当我单击listview项时,我希望看到它们存储在cacha中的服务中的所有项,android,mysql,android-studio,Android,Mysql,Android Studio,我应用缓存,但它只工作一次,当我点击第一个项目时,它会显示数据,然后当我点击另一个项目时,它会显示相同的数据。如何修复它 这是我的密码 String URL = "http://facekart.azanic.com/Data_show_all_.php"; final ProgressDialog progressDialog = new ProgressDialog(getContext()); progressDialog.setMes
String URL = "http://facekart.azanic.com/Data_show_all_.php";
final ProgressDialog progressDialog = new ProgressDialog(getContext());
progressDialog.setMessage("Fetcing, please wait...");
progressDialog.show();
StringRequest request = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
@Override
public void onResponse(String s) {
progressDialog.dismiss();
try {
JSONObject jsonObject = new JSONObject(s);
JSONArray jsonArray = jsonObject.getJSONArray("result");//getting array
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject1 = jsonArray.getJSONObject(i);
Itemssetget it = new Itemssetget();
it.setName(jsonObject1.getString("name"));
it.setPhonenumber_seller(jsonObject1.getString("phonenumber_seller"));
it.setPrice(jsonObject1.getString("price"));
it.setDiscountprice(jsonObject1.getString("discountprice"));
it.setUnits(jsonObject1.getString("units"));
it.setStock(jsonObject1.getString("stock"));
it.setId(jsonObject1.getString("key_auto"));
it.setImageurl("http://facekart.azanic.com/images/" + jsonObject1.getString("imageurl"));
if (it.getStock().toString().equals("In stock")) {
items_random.add(it);
}
}
if (!items_random.isEmpty() && getActivity() != null) {
myAdapter = new homebuyer_fruits_adapter(getActivity(), items_random, homebuyer.phone_number_shop);
myAdapter.notifyDataSetChanged();
Random_list.addHeaderView(random_v);
Random_list.setAdapter(myAdapter);
Random_list.setSmoothScrollbarEnabled(true);
loadingdataprogress.stopShimmerAnimation();
loadingdataprogress.setVisibility(View.INVISIBLE);
// Toast.makeText(getContext(),"ADDED",Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
Toast.makeText(getContext(), "Some error occurred -> " + volleyError, Toast.LENGTH_LONG).show();
;
}
}) {
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
try {
Cache.Entry cacheEntry = HttpHeaderParser.parseCacheHeaders(response);
if (cacheEntry == null) {
cacheEntry = new Cache.Entry();
}
final long cacheHitButRefreshed = 3 * 60 * 1000; // in 3 minutes cache will be hit, but also refreshed on background
final long cacheExpired = 24 * 60 * 60 * 1000; // in 24 hours this cache entry expires completely
long now = System.currentTimeMillis();
final long softExpire = now + cacheHitButRefreshed;
final long ttl = now + cacheExpired;
cacheEntry.data = response.data;
cacheEntry.softTtl = softExpire;
cacheEntry.ttl = ttl;
String headerValue;
headerValue = response.headers.get("Date");
if (headerValue != null) {
cacheEntry.serverDate = HttpHeaderParser.parseDateAsEpoch(headerValue);
}
headerValue = response.headers.get("Last-Modified");
if (headerValue != null) {
cacheEntry.lastModified = HttpHeaderParser.parseDateAsEpoch(headerValue);
}
cacheEntry.responseHeaders = response.headers;
final String jsonString = new String(response.data,
HttpHeaderParser.parseCharset(response.headers));
return Response.success(new String(jsonString), cacheEntry);
} catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
}
}
@Override
protected void deliverResponse(String s) {
super.deliverResponse(s);
}
@Override
public void deliverError(VolleyError error) {
super.deliverError(error);
}
//adding parameters to send
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("s_number", homebuyer.phone_number_shop);
parameters.put("trig", "all");
return parameters;
}
};
RequestQueue rQueue = Volley.newRequestQueue(getContext());
rQueue.add(request);
stringurl=”http://facekart.azanic.com/Data_show_all_.php";
final ProgressDialog ProgressDialog=新建ProgressDialog(getContext());
setMessage(“Fetching,请稍候…”);
progressDialog.show();
StringRequest=newStringRequest(request.Method.POST,URL,new Response.Listener()){
@凌驾
公共void onResponse(字符串s){
progressDialog.disclose();
试一试{
JSONObject JSONObject=新的JSONObject;
JSONArray JSONArray=jsonObject.getJSONArray(“结果”);//获取数组
for(int i=0;i”+截击错误,Toast.LENGTH_LONG).show();
;
}
}) {
@凌驾
受保护的响应parseNetworkResponse(NetworkResponse响应){
试一试{
Cache.Entry cacheEntry=HttpHeaderParser.parseCacheHeaders(响应);
if(cacheEntry==null){
cacheEntry=new Cache.Entry();
}
final long cachehitbutrefresh=3*60*1000;//3分钟后将命中缓存,但也会在后台刷新
final long cacheExpired=24*60*60*1000;//24小时后此缓存项完全过期
long now=System.currentTimeMillis();
最终长时间softExpire=now+cacheHitButRefreshed;
最终长ttl=现在+缓存过期;
cacheEntry.data=response.data;
cacheEntry.softTtl=softExpire;
cacheEntry.ttl=ttl;
字符串头值;
headerValue=response.headers.get(“日期”);
if(headerValue!=null){
cacheEntry.serverDate=HttpHeaderParser.parseDateAsEpoch(headerValue);
}
headerValue=response.headers.get(“上次修改”);
if(headerValue!=null){
cacheEntry.lastModified=HttpHeaderParser.parseDateAsEpoch(headerValue);
}
cacheEntry.responseHeaders=response.headers;
最终字符串jsonString=新字符串(response.data,
HttpHeaderParser.parseCharset(response.headers));
返回Response.success(新字符串(jsonString),cacheEntry);
}捕获(不支持的编码异常e){
返回Response.error(新的ParseError(e));
}
}
@凌驾
受保护的void deliverResponse(字符串s){
超级交付响应;
}
@凌驾
公共无效交付错误(截击错误){
super.deliverError(错误);
}
//添加要发送的参数
@凌驾
受保护的映射getParams()引发AuthFailureError{
映射参数=新的HashMap();
参数.put(“s_编号”、购房者、电话号码、商店);
参数。put(“trig”、“all”);
返回参数;
}
};
RequestQueue rQueue=Volley.newRequestQueue(getContext());
rQueue.add(请求);
提前感谢如果有人在这方面帮助我我想要每个项目点击它显示数据但第一次从服务中获得第二次从缓存中使用任何其他方法你也可以建议我如何平滑我的应用程序
我不想一次又一次地加载