我有一个真正的问题,我不知道如何解决它, 我尝试在我的应用程序上使用sharedpreferences来保存listview上的一些项目。 因为当我没有互联网我有我的apllication exeption所以我尝试保存信息,当我没有connexion,我使用sharedpreferences,但我不知道如何使用它在主或上我的适配器,因为我有很多的TextView从主我在这里的asynchtask:SharedPreferences与列表视图
class FetchRecentPosts extends AsyncTask<Void, Void, Void> {
private ProgressDialog progressDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = ProgressDialog.show(MainActivity.this, "", getString(R.string.loading_message));
}
@Override
protected Void doInBackground(Void... params) {
articles = Services.getRecentPosts();
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
for (Article article : articles) {
System.out.println(article.getTitle());
}
progressDialog.dismiss();
ArticlesAdapter adapter = new ArticlesAdapter(MainActivity.this, R.layout.list_item, articles);
articlesList.setAdapter(adapter);
}
,这是我的适配器
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = convertView;
Article article = getItem(position);
if (convertView == null) {
view = inflater.inflate(R.layout.list_item, null);
image = (ImageView) view.findViewById(R.imageviews.imgArticle);
TextView txtArticleTitle = (TextView) view.findViewById(R.textviews.txtArticleTitle);
TextView txtArticleExcerpt = (TextView) view.findViewById(R.textviews.txtArticleExcerpt);
TextView txtArticleDate = (TextView) view.findViewById(R.id.textArticleDate);
txtArticleTitle.setText(ArabicUtilities.reshape(article.getTitle()));
txtArticleExcerpt.setText(ArabicUtilities.reshape(article.getExcerpt()));
txtArticleDate.setText(article.getDate().toGMTString());
Typeface tf = Typeface.createFromAsset(view.getContext().getAssets(), "fonts/Roboto-Regular.ttf");
txtArticleTitle.setTypeface(tf);
imageLoader.displayImage(article.getImg(), image, options);
}
return view;
}
你想在SharedPreferences保存什么什么都?你得到的例外是什么?究竟是什么问题? – SimonSays 2013-04-24 16:31:27
我从json返回信息。当我有互联网时,一切都很好,但是当没有互联网时,应用程序停止,我想要保存这些信息,当我开始我的应用程序时显示最后一条信息,意味着有一个离线应用程序。 – Sherlock 2013-04-24 16:37:52