如何使用Android在文件中创建一个url字符串,以便以后可以调用它们

时间:2015-06-22 21:41:45

标签: java android list

我是Android开发人员,我试图找出如何回调文件中的某个字符串,以便在另一个活动中将其用作WebView中的URL。要记住,文件中可以有多个字符串,假设我想要一个基于我按下的按钮的特定字符串。

这是我的代码:

    public class LoadArticle extends ActionBarActivity {

MainAct mainStuff;
WebView wv;
Button myButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_load_article);
   // wv = (WebView) findViewById(R.id.webview);

    MainAct mainStuff = this.mainStuff;



    while(mainStuff.listOfUrls.isEmpty()!= true)
    {
        myButton = new Button(this);
        myButton.setText("Push Me");

        LinearLayout ll = (LinearLayout)findViewById(R.id.buttonLay);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        ll.addView(myButton, lp);

        myButton.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {

                try {
                    FileInputStream fileIS = openFileInput("file.txt");
                    int read = -1;
                    StringBuffer buffer = new StringBuffer();
                    while((read = fileIS.read()) != -1) {


                        buffer.append((char)read);
                    }

                    String urlWV = buffer.substring(0, buffer.indexOf("<>"));

                    Intent intent = new Intent(LoadArticle.this,MainAct.class);
                    //intent.putExtra("theURL", urlWV);
                    startActivity(intent);


                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        });
    }

}

0 个答案:

没有答案