0

嗨,当我单击列表视图中的特定项目时,我当前的示例代码使用并打开了浏览 器com/guide/webapps/webview.html

但我不确定我需要如何将下面的代码方法替换为 webview。请帮忙。(注意以防万一你需要知道 getLink 方法是什么,它只是解析一个 xml 来找到链接的节点)

import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
//Get reference to our ListView
sitesList = (ListView)findViewById(R.id.sitesList);

//Set the click listener to launch the browser when a row is clicked.
sitesList.setOnItemClickListener(new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> parent, View v, int pos,long id) {


        String url = mAdapter.getItem(pos).getLink();
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse(url));
                    startActivity(i);


    }

}
4

1 回答 1

0

Check below link, you will get small example demo for webview.

http://www.mkyong.com/android/android-webview-example/

Check below code, replace below code to your existing code:

 String url = mAdapter.getItem(pos).getLink();
                    Intent i = new Intent(this, WebViewActivity.class);
                    i.putExtra("URL",Uri.parse(url));
                    startActivity(i);

After did this, create new class WebViewActivity, declare webview in xml, and then refer the link given, you will get idea.

于 2013-10-01T07:14:25.923 回答