Faire le clic sur un bouton d'un Android
Bonjour j ai cherché sur le forum mais j ai pas trouve de reponse voila j ai un listview qui appelle quand on clic un webview et affiche le html voulu jusque la pas de pb quand j affiche le webview je recupere le titre avec le textview impeccable le pb est que j ai cree un bouton menu pour revenir a la liste de choix mais j arrive pas a l active des que je met un oncliclistener(this) il me claque une erreur merci de votre aide.
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
| package com.psy.loleas;
import java.io.InputStream;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
public class Victimes extends Activity implements OnClickListener{
TextView Titre;
Button Menu;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
{
setContentView(R.layout.viewliste);
LinearLayout monInclude = (LinearLayout)findViewById(R.id.linearLayout1);
Menu =(Button)monInclude.findViewById(R.id.bmenu);
Menu.setOnClickListener(this);
TextView titreText = (TextView)monInclude.findViewById(R.id.textView1);
titreText.setText("Victimes");
// Creation du Parser pour raw/categorie.xml
Parser countryParser = new Parser();
InputStream inputStream = getResources().openRawResource(
R.raw.victimes);
// Parse the inputstream
countryParser.parse(inputStream);
// Get Countries
List<Categorie> countryList = countryParser.getList();
// Create a customized ArrayAdapter
CategorieArrayAdapter adapter = new CategorieArrayAdapter(
getApplicationContext(), R.layout.categorie_listitem, countryList);
// Get reference to ListView holder
ListView lv = (ListView) this.findViewById(R.id.listView1);
lv.setOnItemClickListener(new OnItemClickListener() { |
Ici debut de l appel de la listview et pb pour faire le clic sur le boutonMenu2 onclicListener
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
|
public void onItemClick(AdapterView<?> parent, View view, int position, long duration)
{
/** Called when the activity is first created. */
setContentView(R.layout.webviewfiches);
LinearLayout monInclude = (LinearLayout)findViewById(R.id.linearLayoutwebfiche);
Button Menu2 =(Button)monInclude.findViewById(R.id.bmenu2);
Menu2.setOnClickListener();
TextView titreText = (TextView)monInclude.findViewById(R.id.textView1);
final WebView mWebView = (WebView) findViewById(R.id.webView1);
WebSettings webSettings = mWebView.getSettings();
webSettings.setSaveFormData(true);
webSettings.getLoadsImagesAutomatically();
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(false);
String onItemClick = null;
OnClickListener l = null;
Menu2.setOnClickListener(l);
switch (position) {
case 0:
titreText.setText("Titre");
mWebView.loadUrl("file:///android_asset/html/info.html");
break;
case 1:
titreText.setText("test");
mWebView.loadUrl("file:///android_asset/html/test.html");
break;
case 2:
titreText.setText("");
mWebView.loadUrl("file:///android_asset/html/.html");
break;
case 3:
titreText.setText("");
mWebView.loadUrl("file:///android_asset/html/.html");
break;
case 4:
titreText.setText("");
mWebView.loadUrl("file:///android_asset/html/.html");
break;
case 5:
titreText.setText("");
mWebView.loadUrl("file:///android_asset/html/.html");
break;
case 6:
titreText.setText("");
mWebView.loadUrl("file:///android_asset/html/.html");
break;
case 7:
titreText.setText("");
mWebView.loadUrl("file:///android_asset/html/.html");
break;
case 8:
titreText.setText("");
mWebView.loadUrl("file:///android_asset/html/.html");
break;
case 9:
titreText.setText("");
mWebView.loadUrl("file:///android_asset/html/.html");
break;
case 10:
titreText.setText("");
mWebView.loadUrl("file:///android_asset/html/.html");
break;
case 11:
titreText.setText("");
mWebView.loadUrl("file:///android_asset/html/.html");
break;
}
}
// if(position == 0) {
// Intent intent = new Intent(getApplicationContext(), Listecardio.class);
// startActivity(intent);
//
// }
// Toast.makeText(getApplicationContext(),"afficher texte", Toast.LENGTH_SHORT).show();
});
// Set the ListView adapter
lv.setAdapter(adapter);
}
} |
fin du listview
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
public void onClick(View v) {
// Gestion du clic sur le bouton menu
if(v == Menu) {// appel de la classe desirée
Intent menuIntent = new Intent (this,Accueil.class);
startActivity(menuIntent);
finish();
}
}
} |
Merci pour toute info