关于动态更新 安卓 TExtview的 代码
来源:互联网 发布:unity3d 室内漫游 编辑:程序博客网 时间:2024/05/29 13:23
package com.example.newtest;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONObject;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;
public class addressActivity extends Activity{
private TextView address_location;
private TextView address_location;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.address_activity);
address_location = (TextView)findViewById(R.id.address_now);
address_location.setText("定位中...");
new Thread(){
public void run(){
HttpClientUtil httpClient = new HttpClientUtil();
String getjsonstring = httpClient.getJsonContent("http://ip.taobao.com/service/getIpInfo2.php?ip=myip").toString();
try {
final JSONObject obj = new JSONObject(getjsonstring);
final String token = obj.getString("data");
try {
final JSONObject obj2 = new JSONObject(token);
String token1 = obj2.getString("region");
String token2 = obj2.getString("city");
SharedPreferences settings = getSharedPreferences("persondata",MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
Message message = new Message();
message.what = 1;
Bundle bundle = new Bundle();
bundle.putString("region",token1); //往Bundle中存放数据
bundle.putString("city",token2); //往Bundle中存放数据
message.setData(bundle);//mes利用Bundle传递数据
handler.sendMessage(message);
editor.putString("region",token1);
editor.putString("city",token2);
editor.commit();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
}
private Handler handler = new Handler(){
public void handleMessage(Message msg){
String str1 = msg.getData().getString("region");//接受msg传递过来的参数
String str2 = msg.getData().getString("city");//接受msg传递过来的参数
address_location = (TextView)findViewById(R.id.address_now);
address_location.setText(str1+" "+ str2);
super.onCreate(savedInstanceState);
setContentView(R.layout.address_activity);
address_location = (TextView)findViewById(R.id.address_now);
address_location.setText("定位中...");
new Thread(){
public void run(){
HttpClientUtil httpClient = new HttpClientUtil();
String getjsonstring = httpClient.getJsonContent("http://ip.taobao.com/service/getIpInfo2.php?ip=myip").toString();
try {
final JSONObject obj = new JSONObject(getjsonstring);
final String token = obj.getString("data");
try {
final JSONObject obj2 = new JSONObject(token);
String token1 = obj2.getString("region");
String token2 = obj2.getString("city");
SharedPreferences settings = getSharedPreferences("persondata",MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
Message message = new Message();
message.what = 1;
Bundle bundle = new Bundle();
bundle.putString("region",token1); //往Bundle中存放数据
bundle.putString("city",token2); //往Bundle中存放数据
message.setData(bundle);//mes利用Bundle传递数据
handler.sendMessage(message);
editor.putString("region",token1);
editor.putString("city",token2);
editor.commit();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
}
private Handler handler = new Handler(){
public void handleMessage(Message msg){
String str1 = msg.getData().getString("region");//接受msg传递过来的参数
String str2 = msg.getData().getString("city");//接受msg传递过来的参数
address_location = (TextView)findViewById(R.id.address_now);
address_location.setText(str1+" "+ str2);
}
};
}
};
}
0 0
- 关于动态更新 安卓 TExtview的 代码
- 安卓java 代码中动态实现 TextView的 DrawableTop属性
- 安卓textview代码换行
- 关于安卓 TextView 添加点击事件
- 关于安卓基础迟迟没更新的原因
- 关于安卓开发的一些tips(持续更新)
- 安卓间隔一定时间之后动态更新视图【代码实现】
- 安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom
- 安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom
- 安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom
- 安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom
- 安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom
- 安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom
- 安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom
- 安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom
- 安卓笔记-可以滚动的TextView
- 安卓自定义的渐变TextView
- 关于安卓6.0权限的动态获取
- Oracle EBS中设置项目字段必填
- CASpringAnimation使用和属性解析
- C++第一次实验1-1
- 最小生成树-Prim算法和Kruskal算法
- AJAX from提交出现乱码 各种解决方案
- 关于动态更新 安卓 TExtview的 代码
- Redis安装和启动
- [树链剖分 线段树 标记永久化] BZOJ 4515 [Sdoi2016]游戏
- svn“Previous operation has not finished; run 'cleanup' if it was interrupted“解决方法
- 使用Cocos开发一款简单的3D VR抓钱游戏
- BLE蓝牙在Android开发中的应用(一)
- 解决Android签名混淆后WebView与JS交互失效的问题
- Hbase总结(六)hbase37个笔试题
- Xcode磁盘空间大清理