使用另一个MainActivity?它有用吗?

时间:2014-08-29 00:17:06

标签: java tabs android-asynctask jsoup

这样做可以吗?创建另一个MainAcitivity,因为我的原始MainAcitivity绑定在v4.view.pager activity_main上。虽然,此代码不会发布错误,但此类似乎没有反映输出。我正在使用标签寻呼机适配器。我需要刷新还是什么? (即使此类上的clickAction不起作用,也没有做任何事情。

 public class MainActivity2 extends Activity {

 String url = "http://blog.compassion.com/living-in-the-philippines-rural-life/";
 ProgressDialog mProgressDialog;

 @Override
 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home_fragment);

    TextView titlebutton = (TextView) findViewById(R.id.TextView01);
    titlebutton.setOnClickListener(new OnClickListener() {
        public void onClick(View arg0) {
            // Execute Title AsyncTask
            new Title().execute();
        }
    });


  }

  private class Title extends AsyncTask<Void, Void, Void> {
    String body;
    String title;

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        mProgressDialog = new ProgressDialog(MainActivity2.this);
        mProgressDialog.setTitle("Android Basic JSoup Tutorial");
        mProgressDialog.setMessage("Loading...");
        mProgressDialog.setIndeterminate(false);
        mProgressDialog.show();
    }

    @Override
    protected Void doInBackground(Void... params) {
        try {
            Document document = Jsoup.connect(url).get();
            Elements elements = document.select("p");
            title = document.title();
           for(Element elements123 : elements){
           body+=elements123.text();
           System.out.println(elements123.text());

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

    @Override
    protected void onPostExecute(Void result) {
        TextView txttbody = (TextView) findViewById(R.id.textView2);
        txttbody.setMovementMethod(new ScrollingMovementMethod());
        txttbody.setText(title +"\n"+body);
        mProgressDialog.dismiss();
    }
}

}

0 个答案:

没有答案