我有一个真正的问题,我不知道如何解决它,我尝试在我的应用程序上使用 sharedpreferences 将一些项目保存在 listview 上。因为当我没有互联网时,我的应用程序有例外,所以我尝试保存信息以在我没有连接时拥有它,我使用了 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;
}