我们如何加载以前加载的图像显示在android截取的脱机视图中 *********我正在创建一个具有列表视图的应用程序,它显示网络图像视图和文本视图*********

我们如何加载以前加载的图像显示在android截取的脱机视图中 *********我正在创建一个具有列表视图的应用程序,它显示网络图像视图和文本视图*********,android,android-volley,Android,Android Volley,当internet打开时,但当我进入脱机模式时,它不会在缓存内存中显示我以前加载的图像。在我的主类代码下面,当我尝试脱机工作时,它直接进入json数组,这是错误的 public class MainActivity extends Activity { private static final String TAG = MainActivity.class.getSimpleName(); private ListView listView; private Cust

当internet打开时,但当我进入脱机模式时,它不会在缓存内存中显示我以前加载的图像。在我的主类代码下面,当我尝试脱机工作时,它直接进入json数组,这是错误的

 public class MainActivity extends Activity {

    private static final String TAG = MainActivity.class.getSimpleName();
    private ListView listView;
    private CustomListAdapter listAdapter;
    private List<item> items;
    private ProgressDialog mdialog;
    private String URL_FEED = "json URL"


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        listView = (ListView) findViewById(R.id.list);
        items = new ArrayList<item>();
        listAdapter = new CustomListAdapter(this, items);
        listView.setAdapter(listAdapter);
        Cache cache = AppController.getInstance().getRequestQueue().getCache();
        Entry entry = cache.get(URL_FEED);
        if (entry != null)
        {
            // fetch the data from cache
            try {
                String data = new String(entry.data, "UTF-8");

                Log.d("Internet NO", "Response: " + data);
                try {
                    //parseJsonFeed(new JSONObject(data));
                    JSONArray jsonArray=new JSONArray(data);
                    setData(jsonArray,true);
                    Toast.makeText(getApplicationContext(), "Loading from cache.", Toast.LENGTH_SHORT).show();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }

        }else {

            callJsonArrayRequest();` }

    }

    private void callJsonArrayRequest()
    {
        // TODO Auto-generated method stub
//        showDialog();
        JsonArrayRequest jsonarrayReq = new JsonArrayRequest(URL_FEED,
                new Response.Listener<JSONArray>() {
                    @Override
                    public void onResponse(JSONArray response) {
                        setData(response,false);
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                VolleyLog.d(TAG, "Error: " + error.getMessage());
                Toast.makeText(getApplicationContext(),
                        error.getMessage(), Toast.LENGTH_SHORT).show();
                //dismissDialog();
            }
        });
        // Adding request to request queue
        AppController.getInstance().addToRequestQueue(jsonarrayReq);
    }
    private void setData(JSONArray response, Boolean isCache) {
        Log.d(TAG, response.toString());
        try {
            for (int i = 0; i < response.length(); i++) {
                JSONObject person = (JSONObject) response.get(i);
                item model=new item();
                model.setSname(person.getString("Name"));
                model.setPimage(person.getString("image"));
                items.add(model);
            }
        } catch (JSONException e) {
            e.printStackTrace();
            Toast.makeText(getApplicationContext(),"Error: " + e.getMessage(),Toast.LENGTH_LONG).show();
        }
        listAdapter.notifyDataSetChanged();
        if(!isCache){
            Toast.makeText(getApplicationContext(), "Cache not available..Loading from service", Toast.LENGTH_SHORT).show();
            //dismissDialog();
        }
    }
`
公共类MainActivity扩展活动{
私有静态最终字符串标记=MainActivity.class.getSimpleName();
私有列表视图列表视图;
私有CustomListAdapter-listAdapter;
私人清单项目;
私人住宅;
私有字符串URL\u FEED=“json URL”
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView=(listView)findViewById(R.id.list);
items=newarraylist();
listAdapter=新的CustomListAdapter(此,项);
setAdapter(listAdapter);
缓存缓存=AppController.getInstance().getRequestQueue().getCache();
Entry=cache.get(URL\u提要);
if(条目!=null)
{
//从缓存中获取数据
试一试{
字符串数据=新字符串(entry.data,“UTF-8”);
Log.d(“互联网编号”,“响应:+数据”);
试一试{
//parseJsonFeed(新的JSONObject(数据));
JSONArray JSONArray=新的JSONArray(数据);
setData(jsonArray,true);
Toast.makeText(getApplicationContext(),“从缓存加载”,Toast.LENGTH\u SHORT.show();
}捕获(JSONException e){
e、 printStackTrace();
}
}捕获(不支持的编码异常e){
e、 printStackTrace();
}
}否则{
callJsonArrayRequest();`}
}
私有void callJsonArrayRequest()
{
//TODO自动生成的方法存根
//showDialog();
JsonArrayRequest jsonarrayReq=新的JsonArrayRequest(URL_提要,
新的Response.Listener(){
@凌驾
公共void onResponse(JSONArray响应){
setData(响应,错误);
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
d(标记“Error:+Error.getMessage());
Toast.makeText(getApplicationContext(),
错误.getMessage(),Toast.LENGTH_SHORT).show();
//dismissDialog();
}
});
//将请求添加到请求队列
AppController.getInstance().addToRequestQueue(jsonarrayReq);
}
私有void setData(JSONArray响应,布尔值isCache){
Log.d(TAG,response.toString());
试一试{
对于(int i=0;i
分号后面有一个奇怪的字符:
callJsonArrayRequest();`}
我已经删除了这个字符,但它不起作用……分号后面有一个奇怪的字符:
callJsonArrayRequest();`}我已删除该字符,但它无法工作。。。