gpt4 book ai didi

java - 刷新 Activity 内容或添加刷新按钮

转载 作者:行者123 更新时间:2023-11-29 05:55:18 24 4
gpt4 key购买 nike

因为我可以刷新一个 Activity 的内容?比如我有一个菜单和一个按钮给我发送一个应用内容,在线显示信息,但是要回去再返回,信息没有更新。

这是我的 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(R.id.cerrar);
buttonExit.setOnClickListener(
new View.OnClickListener() {
public void onClick(View v) {
System.exit(0);
}
}
);


TextView myListView = (TextView) findViewById(R.id.tv);
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("http://www.bovalpo.com/cgi-local/xml_bcv.pl?URL=1").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();
}

最佳答案

把你的代码放在这里

@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();

// make your work to data bind


}

关于java - 刷新 Activity 内容或添加刷新按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12390203/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com