refresh content of Activity or add refresh button

As I can refresh the content of an activity?, for example, I have a menu and a button send me an application content that displays information online, but to go back and return again, the information is not updated. This is my Activity. public class Bovalpo extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_bovalpo); Button buttonExit = (Button)this.findViewById(; buttonExit.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { System.exit(0); } } ); TextView myListView = (TextView) findViewById(; try { myListView.setText(getPage()); if(getPage().contains("Abierto")){ myListView.setTextColor(Color.parseColor("#008000")); }else{ myListView.setTextColor(Color.parseColor("#FF0000")); } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private String getPage() throws MalformedURLException, IOException { HttpURLConnection con = (HttpURLConnection) new URL("").openConnection(); con.connect(); if (con.getResponseCode() == HttpURLConnection.HTTP_OK) { return inputStreamToString(con.getInputStream()); } else { return null; } } private String inputStreamToString(InputStream in) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in)); StringBuilder stringBuilder = new StringBuilder(); String line = null; while ((line = bufferedReader.readLine()) != null) { stringBuilder.append("Mercado: " + line + "\n"); } bufferedReader.close(); return stringBuilder.toString(); } public void lanzar(View view){ Intent i = new Intent(this, xml7009.class); startActivity(i); } public void lanzar3(View view){ Intent i = new Intent(this, tabla7009.class); startActivity(i); } public void lanzar4(View view){ Intent i = new Intent(this, xml6503.class); startActivity(i); } public void onClick(View arg0) { // TODO Auto-generated method stub finish(); } }
Note that doing IO on the UI thread (as you do in onCreate() when calling getPage()) may cause Android to force-close your application. Check out AsyncTask for how to do IO in a separate thread. This will also make your UI more responsive. The same applies to any of the other lifecycle methods like onStart(), onResume(), etc. as well, don't do IO in them.

以上就是refresh content of Activity or add refresh button的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准