[英]Open a new activity for each list item clicked from webview
I am loading html file from asset folder in a webview. 我正在从Web视图中的资产文件夹加载html文件。 There is an unordered list.
有一个无序列表。 I want to open a new activity when each list item is clicked.
单击每个列表项时,我想打开一个新活动。 This is what I was trying so far.
到目前为止,这是我一直在尝试的方法。 But it shows file not found error.
但是它显示文件未找到错误。 I am attaching a picture of my desired scenario.
我正在附上我期望的情况的图片。 Please have a look at that.
请看看。 It will help you understand my problem.
它将帮助您了解我的问题。 Wanted Scenario
想要的场景
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 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>
This is the html file. 这是html文件。 This file is in the TopicDetails class.
该文件在TopicDetails类中。 I want to open PrachinYug, Madhyaug and AdhunikYug class when respective item is clicked in the list.
在列表中单击相应项目时,我想打开PrachinYug,Madhyaug和AdhunikYug类。 The target classes are not webview.
目标类不是webview。 They are android listview.
他们是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>
Main Activity: 主要活动:
@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 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.