У меня есть четыре кнопки изображения в screen1.xml. Я определил webview в screen3.xml. Если я нажму кнопку ImageButton1 или другие кнопки, предполагаемый URL (в веб-просмотре) должен загрузиться в screen3.xml.Android: Как открыть webview на новом экране
Я попытался сделать это, но он вызывает силовую ошибку. Но если я попробую то же самое с webview, определенным в screen1.xml, он будет работать. Но проблема в том, что кнопки изображения и веб-просмотр отображаются на одной странице, и они перекрываются, что выглядит ужасно!
Пожалуйста, помогите мне открыть веб-обзор на новом экране.
BTW, можно использовать addView для этой цели?
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>
Благодарим за ответ. Как сказал Jorgesys, я попытался найти, что не так в моем коде. Я должен добавить эту строку «webView = (WebView) findViewById (R.id.web_view)», в метод openbrowser1(). Также мне нужно удалить атрибуты «webview» из screen1.xml. Именно по этой причине я получал FC, когда пытался загрузить веб-просмотр на экране 3. – emmarbe