将webview链接添加到收藏夹

将webview链接添加到收藏夹,webview,favorites,Webview,Favorites,我正在开发新闻应用程序,它在webview中显示了50多个新闻站点,用户可以打开链接并阅读新闻。我想将一些新闻保存为标题或它们的链接,并在收藏夹页面中显示它们。阅读后,可以点击并删除收藏夹中的页面。我用长按页面写入链接到文件的想法,然后阅读文件并列出收藏夹。我用文本视图进行了测试,编写文件似乎还可以,但读取文件却不行。我的代码是: @Override public View onCreateView(LayoutInflater inflater, ViewGroup container

我正在开发新闻应用程序,它在webview中显示了50多个新闻站点,用户可以打开链接并阅读新闻。我想将一些新闻保存为标题或它们的链接,并在收藏夹页面中显示它们。阅读后,可以点击并删除收藏夹中的页面。

我用长按页面写入链接到文件的想法,然后阅读文件并列出收藏夹。我用文本视图进行了测试,编写文件似乎还可以,但读取文件却不行。我的代码是:

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View myInflater= inflater.inflate(R.layout.fragment_main, container, false);

    TextView txtView = (TextView) myInflater.findViewById(R.id.txtView);
    txtView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            // TODO Auto-generated method stub
            Toast.makeText(getActivity(),
                    "You have pressed it long :)", Toast.LENGTH_LONG).show();

            String filename ="favoritessss.txt";
            File file = new File(getActivity().getFilesDir(), filename);
            File directory = getActivity().getDir("SunShine", Context.MODE_WORLD_READABLE);

            //String filename = "myfile";
            String string = "Hello world000000000!"+"\r\n";
            FileOutputStream outputStream;

            try {
                outputStream = getActivity().openFileOutput(filename, Context.MODE_WORLD_WRITEABLE);
                outputStream.write(string.getBytes());
                outputStream.close();
            } catch (Exception e) {
                e.printStackTrace();
        }
        return true;
    }
});

    //Find the view by its id
   final TextView tv = (TextView)myInflater.findViewById(R.id.text_view);

    txtView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            //Find the directory for the SD Card using the API
//不要硬编码“/SD卡” 文件sdcard=getActivity().getFileDir()

//获取文本文件 File File=新文件(SD卡,“favoritessss.txt”); 字符串[]文本=新字符串[15]; 试一试{ BufferedReader br=新的BufferedReader(新文件读取器(文件)); 对于(intj=0;j>15;j++)文本[j]=br.readLine(); br.close(); } 捕获(IOE异常){ //您需要在此处添加正确的错误处理 }

//设置文本 tv.setText(text[0]); Toast.makeText(getActivity(),文本[0], 吐司。长度(短)。show(); } }); 回程充气机; }

有什么评论吗