Android ListView单击“WebBrowser”

时间:2015-03-09 21:29:00

标签: android android-listview android-webview

我创建了一个ListView,并在http链接中添加了一些信息新闻。

当我点击listview

中的一个链接时,我想打开一个Web浏览器

我在array1中添加了信息并添加了链接array2。

我该怎么做?

这是我的代码:

lv = (ListView) findViewById(R.id.listView1);

adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
                newsarraylist);

new NewThread().execute();

}
public class NewThread extends AsyncTask<String, Void, String> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        // Create a progressdialog
        mProgressDialog = new ProgressDialog(MainActivity.this);
        // Set progressdialog title
        mProgressDialog.setTitle("İzmir Üniversitesi Haberleri");
        // Set progressdialog message
        mProgressDialog.setMessage("Yükleniyor...");
        // mProgressDialog.setIndeterminate(false);
        // Show progressdialog
        mProgressDialog.show();
    }
    @Override
    protected String doInBackground(String... params) {
        Document doc;
        try {
            doc = Jsoup.connect(url).get();
            Elements table = doc.select("table.contentpane td:eq(1)");
            Elements links=doc.select("table.contentpane a[href]");
            for (Element tables : table) {
                newsarraylist.add(tables.text());
            }
            for (Element link : links) {
                newarraylistlink.add(link.html());
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(String result) {
        // lv=(ListView)findViewById(R.id.listView1);

        lv.setAdapter(adapter);
        mProgressDialog.dismiss();
    }

}
private void registerClick(){
    ListView list=(ListView)findViewById(R.id.listView1);
    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            myweb=(WebView)findViewById(R.id.mywebview);
            myweb.getSettings().setJavaScriptEnabled(true);
            myweb.loadUrl(newarraylistlink.toString());

        }
    });
}
}

1 个答案:

答案 0 :(得分:0)

您似乎将错误的网址传递给WebViewnewarraylistlinkList,因此您需要将newarraylistlink.get(position)传递给{{1} }}