私は実際の問題を抱えており、それを解決する方法がわかりません。アプリケーションで sharedpreferences を使用して、リストビューに項目を保存しようとしています。私はインターネットを持っていないとき、アプリケーションに例外があるので、接続がないときに情報を保存しようとします.sharedpreferencesを使用しましたが、メインまたは自分でそれを使用する方法がわかりませんでした.アダプターの原因私は多くの textview を持っています.ここでメインからの私の非同期タスク:
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;
}