Sauvegarde d'activité sur bascule écran
Bonjour a la communauté voila mon probleme j ai une listview quand je clic sur un élément cela m affiche une page web contenue dans mon dossier asset par la fonction webview.
jusqu a la pas de pb
Quand j ai la la listview a l ecran je bascule l ecran celui ci ne me ferme pas l activité et je garde ma listview.
par contre quand j ai ma page html a l ecran et que je bascule l ecran sa ferme l activité et je reviens a ma listview. Pourtant j ai bien la fonction:
Code:
1 2
| public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); |
J ai cherche mais je ne vois pas est il possible de mette cette fonction une nouvelle fois que dans ma partie plus bas:
voici mon code :
Code:
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
|
package smur.bmpm;
import java.util.ArrayList;
import smur.bmpm.Protoadapter.PersonneAdapterListener;
import smur.bmpm.R.string;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View.OnClickListener;
import android.view.View;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
public class ProtoMain extends Activity implements PersonneAdapterListener ,OnClickListener {
private WebView mWebView;
Button button = null;
Button button1 = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.proto);
button = (Button)findViewById(R.id.Smur);
button.setOnClickListener(this);
ArrayList<Proto> listP = Proto.getAListOfPersonne();
Protoadapter adapter = new Protoadapter(this, listP);
adapter.addListener(this);
ListView list = (ListView)findViewById(R.id.ListView01);
list.setAdapter(adapter);
}
public void onClick(View v) {
if(v == button) { // Vérification de la vue cliquée
Intent monIntent = new Intent(this,main.class);
startActivity(monIntent);
finish();
}
if(v == button1) { // Vérification de la vue cliquée
Intent monIntent1 = new Intent(this,ProtoMain.class);
startActivity(monIntent1);
finish();
}
}
public void onClickNom(Proto item, int position) {
setContentView(R.layout.webviewproto);
// faut il que je rajoute ici la meme fonction merci de vos conseils
button1=(Button)findViewById(R.id.Proto);
button1.setOnClickListener(this);
mWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setSaveFormData(true);
webSettings.getLoadsImagesAutomatically();
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(true);
mWebView.loadUrl("file:///android_asset/"+item.nomcourt+".html");
}
} |
si quelqu un peut m eclairer car je vois pas comment la garder ouverte sinon merci
sauvegarde de l activité suite
bonjour je reviens toujours pour une question j avais résolu précédemment car j étais passe en static .
Voici mon nouveau code le pb est la quand je clic sur une position je recup bien ma fiche dans mon webview les boutons fonctionne . mais j aimerai faire un savedInstanceState de ma webview quand je bascule l ecran j ai vu que l on pouvait le mettre mettre mais je vois pas trop ou . voici mon code
Code:
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 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
|
public class Listetech extends Activity implements OnClickListener {
private static final AdapterView<ListAdapter> lv = null;
WebView webview;
Button retour;
Button suivant;
Button precedent;
Button apres;
int fiche;
private List<Categorie> countryList= new ArrayList<Categorie>();
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set the View layer
setContentView(R.layout.listview2);
// setTitle("TestIconizedListView");
LinearLayout monInclude = (LinearLayout)findViewById(R.id.include2);
retour =(Button)monInclude.findViewById(R.id.bretour);
retour.setOnClickListener(this);
TextView titreText = (TextView)monInclude.findViewById(R.id.textView1);
titreText.setText("techniques");
CategorieParser countryParser = new CategorieParser();
InputStream inputStream = getResources().openRawResource(
R.raw.tech);
countryParser.parse(inputStream);
List<Categorie> countryList = countryParser.getList();
CategorieArrayAdapter adapter = new CategorieArrayAdapter(
getApplicationContext(), R.layout.categorie_listitem, countryList);
ListView lv = (ListView) this.findViewById(R.id.countryLV);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long duration)
{
setContentView(R.layout.webfiche2);
LinearLayout monInclude = (LinearLayout)findViewById(R.id.layoutwebfiche);
retour=(Button)monInclude.findViewById(R.id.bretour);
precedent=(Button)monInclude.findViewById(R.id.precedent);
suivant=(Button)monInclude.findViewById(R.id.suivant);
((Button) findViewById(R.id.bretour)).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// clic sur le bouton retour initialisé par l activité principal
if(v == retour) {
// appel de la classe desirée
Intent menuIntent = new Intent (Listetech.this,Listetech.class);
startActivity(menuIntent);
finish();
}
}
});
// TextView titreText = (TextView)monInclude.findViewById(R.id.textView1);
final WebView mWebView = (WebView) findViewById(R.id.webview);
// Bouton pour passer a la fiche suivante
((Button) findViewById(R.id.suivant)).setOnClickListener(new OnClickListener() {
public void onClick(View v) { if(v == suivant) {
// appel de la classe desirée
if(fiche<93){
fiche++;
mWebView.loadUrl("file:///android_asset/tech/"+fiche+".png");
}
else{
fiche=79;
mWebView.loadUrl("file:///android_asset/tech/"+fiche+".png");
}}}
});
//Bouton pour revenir a la fiche precedente
((Button) findViewById(R.id.precedent)).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// clic sur le bouton retour initialisé par l activité principal
if(v == precedent) {
// appel de la classe desirée
if(fiche>79){
fiche--;
mWebView.loadUrl("file:///android_asset/tech/"+fiche+".png");
}
else{
fiche=92;
mWebView.loadUrl("file:///android_asset/tech/"+fiche+".png");
}}}
});
WebSettings webSettings = mWebView.getSettings();
webSettings.setSaveFormData(true);
webSettings.getLoadsImagesAutomatically();
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(true);
mWebView.getSettings().setBuiltInZoomControls(true);
int scale = (int) (40* mWebView.getScale());
mWebView.setInitialScale( scale );
switch (position) {
case 0:
mWebView.loadUrl("file:///android_asset/tech/79.png");
fiche = 79;
break;
case 1:
mWebView.loadUrl("file:///android_asset/tech/80.png");
fiche = 80;
break;
case 2:
mWebView.loadUrl("file:///android_asset/tech/82.png");
fiche=82;
break;
case 3:
mWebView.loadUrl("file:///android_asset/tech/83.png");
fiche=83;
break;
case 4:
mWebView.loadUrl("file:///android_asset/tech/84.png");
fiche=84;
break;
case 5:
mWebView.loadUrl("file:///android_asset/tech/85.png");
fiche=85;
break;
case 6:
mWebView.loadUrl("file:///android_asset/tech/86.png");
fiche=86;
break;
case 7:
mWebView.loadUrl("file:///android_asset/tech/87.png");
fiche=87;
break;
case 8:
mWebView.loadUrl("file:///android_asset/tech/88.png");
fiche=88;
break;
case 9:
mWebView.loadUrl("file:///android_asset/tech/89.png");
fiche = 89;
break;
case 10:
mWebView.loadUrl("file:///android_asset/tech/90.png");
fiche = 90;
break;
case 11:
mWebView.loadUrl("file:///android_asset/tech/91.png");
fiche=91;
break;
case 12:
mWebView.loadUrl("file:///android_asset/tech/92.png");
fiche=92;
break;
}
}
});
// Set the ListView adapter
lv.setAdapter(adapter);
}
public void onClick(View v) {
// TODO Auto-generated method stub
if(v == retour) {// appel de l activité score de glasgow
Intent menuIntent = new Intent (this,Accueil.class);
startActivity(menuIntent);
finish();
}
}
public static AdapterView<ListAdapter> getLv() {
return lv;
}
public List<Categorie> getCountryList() {
return countryList;
}
public void setCountryList(List<Categorie> countryList) {
this.countryList = countryList;
}
} |
je pense que je dois pouvoir faire un private void bundle pour sauver ma webview mais je sais pas ou ?.
merci a vous pour vos info