salut tt le monde , j'ai un probléme et j'ai pas trouvé une solution depuis X-temps , j'ai une application qui se crash lors de son ouverture si j'ai pas de connexion , alors je veux enregistrer les données lors que j'ouvre mon application et lors de son ouverture proch fois quand j'aurais pas de connexion me retourne les dernières données enregistrer on utilisant sharedPreferences , voila c'est mon main :


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
public class MainActivity extends SlidingActivity implements OnItemClickListener, OnClickListener{
 
	private ArrayList<Article> articles;
	private ListView articlesList;
	private TextView foot;
	private TextView omnisport;
	private TextView media;
	private TextView rank;
	private TextView program;
	private TextView gall;
	private TextView twitter;
	private TextView fb;
	private TextView yt;
	private ImageView imgmenu;
	private ImageView imginf;
	private String[] data;
	private String array_data;
	@Override
 
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main_view);
 
 
		init();
		checkInternetConnection();
	}
 
 
	private boolean checkInternetConnection() {
		ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
 
		if (cm.getActiveNetworkInfo() != null
				&& cm.getActiveNetworkInfo().isAvailable()
				&& cm.getActiveNetworkInfo().isConnected()) {
			return true;
		} else {
			Log.v("wa makaynash connexion a sahbé :s", null);
			return false;
		}
	}
 
	private void init() {
 
		foot=(TextView)findViewById(R.textviews.txtFoot);
		foot.setOnClickListener(this);
 
		yt=(TextView)findViewById(R.textviews.txtytb);
		yt.setOnClickListener(this);
 
		fb=(TextView)findViewById(R.textviews.txtfb);
		fb.setOnClickListener(this);
 
 
		twitter=(TextView)findViewById(R.textviews.txttw);
		twitter.setOnClickListener(this);
 
		gall=(TextView)findViewById(R.textviews.txtgal);
		gall.setOnClickListener(this);
 
		omnisport=(TextView)findViewById(R.textviews.txtOmnisport);
		omnisport.setOnClickListener(this);
 
		program=(TextView)findViewById(R.textviews.txtprog);
		program.setOnClickListener(this);
 
		media=(TextView)findViewById(R.textviews.txtmedia);
		media.setOnClickListener(this);
 
		rank=(TextView)findViewById(R.textviews.txtclass);
		rank.setOnClickListener(this);
 
		imgmenu =(ImageView)findViewById(R.imageviews.imgMenu);
		imgmenu.setOnClickListener(this);
 
		imginf =(ImageView)findViewById(R.imageviews.imgInfo);
		imginf.setOnClickListener(this);
 
 
		articlesList = (ListView) findViewById(R.listviews.wnlist);
		articlesList.setOnItemClickListener(this);
 
		new FetchRecentPosts().execute();
 
	}
 
 
	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);
 
		}
 
	}
 
	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
 
		Article selectedArticle = (Article) arg0.getItemAtPosition(arg2);
		Intent intent = new Intent(this, ReadArticleActivity.class);
		intent.putExtra("selectedArticle", selectedArticle);
		startActivity(intent);
	}
 
	private void LoadPf(){
		SharedPreferences sp=PreferenceManager.getDefaultSharedPreferences(this);
		Editor edit=sp.edit();
		edit.putString("","");
		edit.commit();
 
 
	}
	private void SavePf(String val1, String val2,String Val3, String val4){
		SharedPreferences sp=PreferenceManager.getDefaultSharedPreferences(this);
		Editor edit=sp.edit();
		edit.putString("","");
		edit.commit();
 
	}
 
	@Override
	public void onClick(View v) {
		if(v.getId() == foot.getId()) {
			new FetchRecentPosts().execute();
 
		} else if(v.getId() == omnisport.getId() ){
			Intent intent = new Intent(MainActivity.this,OmniSports.class);
			startActivity(intent);	
			SavePf("","","","");
			this.finish();
		} else if(v.getId() == media.getId() ){
			Intent intent = new Intent(MainActivity.this,WydadTv.class);
			startActivity(intent);		
			this.finish();
		} else if(v.getId() == program.getId() ){
			Intent intent = new Intent(MainActivity.this,ProgramActivity.class);
			startActivity(intent);		
			this.finish();
		}else if(v.getId() == gall.getId() ){
			Intent intent = new Intent(MainActivity.this,Gallery_Activity.class);
			startActivity(intent);		
		}  else if(v.getId() == rank.getId() ){
			Intent intent = new Intent(MainActivity.this,RankingActivity.class);
			startActivity(intent);		
			this.finish();
		} else if(v.getId() == imginf.getId() ){
			Intent intent = new Intent(MainActivity.this,About.class);
			startActivity(intent);		
		} else if(v.getId() == fb.getId() ){
			Intent intent = new Intent(MainActivity.this,FbActivity.class);
			startActivity(intent);
		} else if(v.getId() == yt.getId() ){
			Intent intent = new Intent(MainActivity.this,YoutubeActivity.class);
			startActivity(intent);
		} else if(v.getId() == twitter.getId() ){
			Intent intent = new Intent(MainActivity.this,TwitterActivity.class);
			startActivity(intent);	
		} else if(v.getId() == imgmenu.getId()) {
			getSlidingMenu().toggle();	
		} 
	}
 
 
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		return super.onOptionsItemSelected(item);
	}
}
et voila mon adapter ce que je veux afficher :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
 
public class ArticlesAdapter extends ArrayAdapter<Article> {
 
	private File cacheDir;
	private ImageLoader imageLoader;
	private ImageLoaderConfiguration config;
	private DisplayImageOptions options;
	private ImageView image;
 
	public ArticlesAdapter(Context context, int textViewResourceId,
			List<Article> objects) {
		super(context, textViewResourceId, objects);
 
		cacheDir = StorageUtils.getOwnCacheDirectory(context, "WydadNewsImageLoader/Cache");
		imageLoader = ImageLoader.getInstance();
 
		config = new ImageLoaderConfiguration.Builder(context)
		.memoryCacheExtraOptions(480, 800)
		.discCacheExtraOptions(480, 800, CompressFormat.JPEG, 75)
		.threadPoolSize(3)
		.threadPriority(Thread.NORM_PRIORITY - 1)
		.denyCacheImageMultipleSizesInMemory()
		.offOutOfMemoryHandling()
		.memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024))
		.discCache(new UnlimitedDiscCache(cacheDir))
		.discCacheFileNameGenerator(new HashCodeFileNameGenerator())
		.imageDownloader(
				new URLConnectionImageDownloader(5 * 1000, 20 * 1000))
				.defaultDisplayImageOptions(DisplayImageOptions.createSimple())
				.build();
		imageLoader.init(config);
		options = new DisplayImageOptions.Builder()
		.showStubImage(R.drawable.ic_launcher)
		.showImageForEmptyUri(R.drawable.ic_launcher).cacheInMemory()
		.cacheOnDisc().imageScaleType(ImageScaleType.POWER_OF_2)
		.build();
	}
 
 
 
	@Override
	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;
	}
 
 
 
}