[英]Open a new activity for each list item clicked from webview
我正在從Web視圖中的資產文件夾加載html文件。 有一個無序列表。 單擊每個列表項時,我想打開一個新活動。 到目前為止,這是我一直在嘗試的方法。 但是它顯示文件未找到錯誤。 我正在附上我期望的情況的圖片。 請看看。 它將幫助您了解我的問題。 想要的場景
wv_topic_details = findViewById(R.id.wv_topic_details);
wv_topic_details.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
Intent intent = new Intent(TopicDetails.this, PrachinYug.class);
startActivity(intent);
return true;
}
});
wv_topic_details.loadUrl(file_path);
webSettings = wv_topic_details.getSettings();
webSettings.setBuiltInZoomControls(true); //enable zoom facility
webSettings.setDisplayZoomControls(false); //hide the zoom control switch
AndroidManifest.xml
<activity
android:name=".TopicDetails"
android:parentActivityName=".MainActivity">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.VIEW"/>
<data android:scheme="prachin_yug"/>
</intent-filter>
</activity>
<activity
android:name=".PrachinYug"
android:label="@string/prachin_yug"
android:parentActivityName=".MainActivity" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.VIEW"/>
<data android:scheme="prachin_yug"/>
</intent-filter>
</activity>
<activity
android:name=".MadhyaYug"
android:label="@string/madhya_yug"
android:parentActivityName=".MainActivity" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.VIEW"/>
<data android:scheme="madhya_yug"/>
</intent-filter>
</activity>
<activity
android:name=".AdhunikYug"
android:label="@string/adhunik_yug"
android:parentActivityName=".MainActivity">
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.VIEW"/>
<data android:scheme="adhunik_yug"/>
</intent-filter>
</activity>
這是html文件。 該文件在TopicDetails類中。 在列表中單擊相應項目時,我想打開PrachinYug,Madhyaug和AdhunikYug類。 目標類不是webview。 他們是android listview。
<p>
আনুমানিক ....... করা যায়। যথা-
</p>
<ul>
<li><a href="prachin_yug">প্রাচীন যুগ</a></li>
<li><a href="madhya_yug">মধ্যযুগ</a></li>
<li><a href="adhunik_yug">আধুনিক যুগ</a></li>
</ul>
主要活動:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webview = findViewById(R.id.webview);
webview.loadUrl("file:///android_asset/yourfile.html");
webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url{
if (url.equals("Your URL inside yourfile.html")) {
startActivity(new Intent(this, YourActivity.class));
}
return true;
}
});
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/webview_contributors"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.