2011-05-16 45 views
0

我刚刚为Fedor的LazyLoading ListView实现了GSON。这意味着应用程序通过ImageLoader类将下载的图像和文本从网络保存到外部存储器。Android:使GSON的LazyLoading ListView可以在没有互联网的情况下使用

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

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; 
     } 
    } 


} 

如果更多的我的代码需要请指教。 感谢

+0

只要在这里写你的代码'catch(Exception e) { //你的代码,,,,,,,} – 2011-05-16 10:10:30

+0

我应该在哪写这个?在onCreate内? – hectichavana 2011-05-16 10:11:46

+0

是的,在'OnCreate'里面..当你没有从你的web服务器得到任何回应时。只要做你想做的事情。 – 2011-05-16 10:44:25

回答

1

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

当你所得到的数据保存在某个地方它在你的application.Then通过数据的Adapter ..

图像将不会再下载...

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

希望这会帮助你。

+0

有趣,你能指导我做这个吗?对不起,因为要求很高,但我在这个 – hectichavana 2011-05-16 11:16:49

+0

是个新手。此链接可以帮助你http://www.google.co.in/#sclient=psy&hl=en&biw=1366&bih=624&source=hp&q=android+sqlite+tutorial&aq = 1&AQI = G5&AQL =&OQ =&PBX = 1&FP = 5104fce57ec41299 – 2011-05-16 11:20:52

相关问题