J'ai quatre boutons Image dans screen1.xml. J'ai défini le webview dans screen3.xml. Si je clique sur le bouton ImageButton1 ou d'autres boutons, l'URL de référence (dans le webview) devrait charger dans screen3.xml.Android: Comment ouvrir le webview dans un nouvel écran
J'ai essayé de le faire, mais il jette forceclose erreur. Mais si j'essaie la même chose avec webview défini dans screen1.xml, cela fonctionne. Mais le problème est les boutons d'image et le webview apparaît dans la même page et ils se chevauchent ce qui est horrible!
S'il vous plaît aidez-moi à ouvrir le webview dans un nouvel écran.
BTW, peut ajouterAvoir être utilisé à cette fin?
public class click extends Activity
{
private WebView webView;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.screen1);
webView = (WebView) findViewById(R.id.web_view);
ImageButton i1 = (ImageButton) findViewById(R.id.imagebutton1);
ImageButton i2 = (ImageButton) findViewById(R.id.imagebutton2);
ImageButton i3 = (ImageButton) findViewById(R.id.imagebutton3);
ImageButton i4 = (ImageButton) findViewById(R.id.imagebutton4);
}
private void openBrowser1()
{
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("myurl");
}
public void myClickHandler1(View view)
{
openBrowser1();
}
Screen1.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView
android:id="@+id/web_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0" />
<ImageButton android:id="@+id/imagebutton1" android:clickable="true" android:onClick="myClickHandler1"
android:layout_width="130dip" android:background="@null" android:layout_height="130dip" android:layout_x="21dip"
android:layout_y="61dip" ></ImageButton>
<ImageButton android:id="@+id/imagebutton2" android:clickable="true" android:onClick="myClickHandler2"
android:layout_width="130dip" android:background="@null" android:layout_height="130dip" android:layout_x="171dip"
android:layout_y="61dip" ></ImageButton>
<ImageButton android:id="@+id/imagebutton3" android:clickable="true" android:onClick="myClickHandler3"
android:layout_width="130dip" android:background="@null" android:layout_height="130dip" android:layout_x="21dip"
android:layout_y="241dip" ></ImageButton>
<ImageButton android:id="@+id/imagebutton4" android:clickable="true" android:onClick="myClickHandler4"
android:layout_width="130dip" android:background="@null" android:layout_height="130dip" android:layout_x="171dip"
android:layout_y="241dip" ></ImageButton>
</AbsoluteLayout>
screen3.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<WebView
android:id="@+id/web_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0" />
</AbsoluteLayout>
Merci pour votre réponse les gars. Comme l'a dit Jorgesys, j'ai essayé de trouver ce qui ne va pas dans mon code. Je dois ajouter cette ligne "webView = (WebView) findViewById (R.id.web_view);" dans la méthode openbrowser1(). De plus, je dois supprimer les attributs "webview" de screen1.xml. C'est la raison pour laquelle, je recevais FC quand j'ai essayé de charger le webview dans l'écran 3. – emmarbe