2

在我的应用程序中,我正在获取默认浏览器中可用的所有书签并将其填充到列表视图中。我想要的是,当我单击特定的 listItem(bookmark) 时,它应该直接在默认浏览器中打开该书签。

String[] requestedColumns = { Browser.BookmarkColumns.TITLE,
                Browser.BookmarkColumns.VISITS,
                Browser.BookmarkColumns.BOOKMARK };

        @SuppressWarnings("deprecation")
        Cursor faves = managedQuery(Browser.BOOKMARKS_URI, requestedColumns,
                Browser.BookmarkColumns.BOOKMARK + "=1", null,
                Browser.BookmarkColumns.VISITS);
        Log.d("Bookmarks", "Bookmarks count: " + faves.getCount());
        int titleIdx = faves.getColumnIndex(Browser.BookmarkColumns.TITLE);
        String url[] = new String[] {android.provider.Browser.BookmarkColumns.URL};
        Log.d("SimpleBookmarks url", url[0]);
        //int url_column_index = faves.getColumnIndexOrThrow(Browser.BookmarkColumns.URL);
        faves.moveToFirst();
        if (bookmark_check) {
            while (!faves.isAfterLast()) {
                Log.d("SimpleBookmarks", faves.getString(titleIdx));

                HashMap<String, Object> map = new HashMap<String, Object>();
                map.put("bookmark", faves.getString(titleIdx));
                map.put("url", "");
                listitem.add(map);
                faves.moveToNext();
            }
        }

        Log.v("data", "" + listitem);
        SimpleAdapter listitemAdapter = new SimpleAdapter(this, listitem,
                R.layout.list_style, new String[] { "bookmark", "url" },
                new int[] { R.id.topTextView, R.id.bottomTextView });
        lv.setAdapter(listitemAdapter); 
4

1 回答 1

2

终于得到了解决方案。

String[] requestedColumns = { Browser.BookmarkColumns.TITLE,
                Browser.BookmarkColumns.URL };

        @SuppressWarnings("deprecation")
        final Cursor faves = managedQuery(Browser.BOOKMARKS_URI,
                requestedColumns, Browser.BookmarkColumns.BOOKMARK + "=1",
                null, null);
        faves.moveToFirst();
        int titleIdx = faves.getColumnIndex(Browser.BookmarkColumns.TITLE);
        final int urlIdx = faves.getColumnIndex(Browser.BookmarkColumns.URL);

        if (bookmark_check) {
            while (!faves.isAfterLast()) {
faves.getString(urlIdx));
                HashMap<String, Object> map = new HashMap<String, Object>();
                map.put("name", faves.getString(titleIdx));
                map.put("phone no", faves.getString(urlIdx));
                listitem.add(map);
                faves.moveToNext();
            }

        }
        SimpleAdapter listitemAdapter = new SimpleAdapter(this, listitem,
                R.layout.list_style, new String[] { "name", "phone no" },
                new int[] { R.id.topTextView, R.id.bottomTextView });
        lv.setAdapter(listitemAdapter);

        lv.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {

                RelativeLayout lr = (RelativeLayout) arg1;
                TextView mText = (TextView) lr.getChildAt(1);
                    String st = mText.getText().toString();
                    if (!st.startsWith("https://") && !st.startsWith("http://")) {
                        st = "http://" + mText.getText().toString();
                    }
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setData(Uri.parse(st));
                    startActivity(i);

            }
        });
于 2013-08-28T11:00:55.083 回答