Android 在项目上单击打开webview中的RSS链接

Android 在项目上单击打开webview中的RSS链接,android,android-fragments,webview,hyperlink,rss,Android,Android Fragments,Webview,Hyperlink,Rss,在我拥有的一个RSS片段中,我相信下面的代码说明了在RSS列表视图中创建一个项目时会发生什么。单击项目时,它将在chrome中打开 @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { RssAdapter adapter = (RssAdapter) parent.getAdapter(); RssItem item = (RssIte

在我拥有的一个RSS片段中,我相信下面的代码说明了在RSS列表视图中创建一个项目时会发生什么。单击项目时,它将在chrome中打开

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    RssAdapter adapter = (RssAdapter) parent.getAdapter();
    RssItem item = (RssItem) adapter.getItem(position);
    Uri uri = Uri.parse(item.getLink());
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    startActivity(intent);
}
XML布局用于:

Rss片段

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" tools:context="yanay.end.TwitterFragment"
android:background="@color/white"
android:paddingLeft="3dp"
android:paddingRight="3dp">

<!-- TODO: Update blank fragment layout -->



<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >


    <ListView
        android:id="@+id/listView"
        android:layout_width="fill_parent"
        android:paddingRight="0dp"
        android:paddingLeft="0dp"
        android:paddingTop="0dp"
        android:paddingBottom="1dp"
        android:layout_height="fill_parent"
        android:divider="@color/blue1"
        android:dividerHeight="3dp"
        >
    </ListView>

    <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />

</RelativeLayout>


</FrameLayout>

和Web视图布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
>

<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none"
/>

</RelativeLayout>


编辑:现在单击链接打开web活动,但我仍然不知道如何将url设置为单击的项目url。

将下面的代码放在RSSFragment的onItemClick中

String urlval = uri + "";
Intent mIntent = new Intent(getActivity(), WebViewActivity.class);
                 mIntent.putExtra(WebViewActivity.URL_KEY, urlval);
startActivity(mIntent);
下面是WebViewActivity中的代码

Bundle extras = getIntent().getExtras();
String url = extras.getString(URL_KEY);
web.loadUrl(url);

它应该会起作用。我也尝试过同样的方法。

将链接以
包的形式传递给你,然后开始你的webview活动。非常基本的安卓系统。
Bundle extras = getIntent().getExtras();
String url = extras.getString(URL_KEY);
web.loadUrl(url);