我刚刚在 Fedor 的 LazyLoading ListView 中实现了 GSON。这意味着应用程序通过 ImageLoader 类将下载的图像和文本从 Web 保存到外部存储中。
我想知道为什么如何在没有互联网连接的情况下访问列表视图?应用程序已经成功将缓存数据保存到 SD 卡中,现在如何调用这些文件?因此,当没有互联网时,它会从 SD 卡中调用数据(文本和图像)。
谢谢。我愿意接受任何类型的解决方案
这是我的 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;
}
}
}