安卓:从可用没有互联网GSON使惰性加载的ListView [英] Android: Make LazyLoading ListView from GSON available without internet

查看:125
本文介绍了安卓:从可用没有互联网GSON使惰性加载的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚实施GSON到费多尔的惰性加载的ListView。这意味着该应用保存从Web下载的图像和文本,以在外部存储虽然一个ImageLoader的类

I've just implemented GSON to Fedor's LazyLoading ListView. That means the app saves the downloaded images and texts from the web to the external storage though an ImageLoader class.

和我不知道为什么如何使这个列表视图没有互联网连接访问。
在这里,我给你我的ListView类的一个片段:

and I wonder why how to make this listview accessible without an internet connection. Here I give you a snippet of my ListView Class:

public class ProjectsList extends Activity {
    ListView lstTest;

    ProjectAdapter arrayAdapter;

    ArrayList<Project> prjcts=null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.projects_list);

        //Initialize ListView
        lstTest= (ListView)findViewById(R.id.lstText);

        prjcts = new ArrayList<Project>();

        arrayAdapter = new ProjectAdapter(ProjectsList.this, R.layout.listitems,prjcts,ProjectsList.this);

            lstTest.setAdapter(arrayAdapter);
            if (isOnline())
            {
        WebService webService = new WebService("http://liebenwald.spendino.net/admanager/dev/android/projects.json");

        Map<String, String> params = new HashMap<String, String>();
        params.put("var", "");

        String response = webService.webGet("", params);

        try
        {
            Type collectionType = new TypeToken<ArrayList<Project>>(){}.getType();
            List<Project> lst= new Gson().fromJson(response, collectionType);


            for(Project l : lst)
            {
                prjcts.add(l);
                ConstantData.projectsList.add(l);
            }

            arrayAdapter.notifyDataSetChanged();
        }
        catch(Exception e)
        {
            Log.d("Error: ", e.getMessage());
        }
       }


        lstTest.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {              
                Intent care = new Intent(ProjectsList.this, ProjectDetail.class);
                care.putExtra("spendino.de.ProjectDetail.position",position);
                startActivity(care);
            }
        });

    }
    @Override
    public void onDestroy()
    {
        yAdapter.imageLoader.stopThread();
        lstTest.setAdapter(null);
        super.onDestroy();
    }

    protected boolean isOnline() {
        ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = cm.getActiveNetworkInfo();
        if (netInfo != null && netInfo.isConnected()) {
            return true;
        } else {
                 }
             });
            return false;
        }
    }


}

如果我多codeS都需要请指教。
谢谢

Please advise if more of my codes are required. Thanks

推荐答案

你看,你需要有数据在您的应用程序,让您可以给他们打电话的时候没有互联网连接可用...

Look, you need to have the data in your application so that you can call them when no internet connection is available...

在你所得到的数据保存到某个地方在application.Then在传递数据的适配器 ..

When you are getting the data save it somewhere in your application.Then pass the data in your Adapter..

图像将不会再下载...

The images will not be downloaded again...

在费多尔的lazylist图像的URL是静态的,但在这里,他们被动态地来了。

In Fedor's lazylist the url of the images are static but here they are coming dynamically.

希望这会帮助你。

这篇关于安卓:从可用没有互联网GSON使惰性加载的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆