我读般的速度,并使用单一吨级个当前位置的一些数据......我读他们使用的AsyncTask线程在一个循环....:)......每次我一次读一本新的速度和位置,我将它们设置在上面的地图文本视图。
这是怎么了我的code部分是这样的:
,而(真){
速度= ServerManager.getInstance()getLastSpeed()。
LOC1 = ServerManager.getInstance()getLastLocation()。
速度= ServerManager.getInstance()getLastSpeed()。
speed_1.setText(Integer.toString(速度));
location.setText(LOC1);
}
其中:
速度是浮子和 LOC1-为String。这是我的XML是这样的:
< RelativeLayout的的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
>
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=横向
机器人:layout_width =FILL_PARENT
机器人:ID =@ + ID /条
机器人:后台=#FFFFFF
机器人:layout_height =WRAP_CONTENT
>
<的TextView
机器人:ID =@ + ID / PROD1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:填充=3dip
机器人:TEXTSIZE =12像素
机器人:文本=当前位置
/>
<的TextView
机器人:ID =@ + ID /位置
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:填充=3dip
机器人:文字颜色=#013220
机器人:TEXTSIZE =12像素
/>
<的TextView
机器人:ID =@ + ID / Prod2的
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:重力=center_horizontal
机器人:以下属性来=90dip
机器人:TEXTSIZE =12像素
机器人:文本=生死时速
/>
<的TextView
机器人:ID =@ + ID /速度
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:填充=3dip
机器人:文字颜色=#013220
机器人:TEXTSIZE =12像素
/>
< / LinearLayout中>
< com.google.android.maps.MapView
机器人:ID =@ + ID / mapview1
机器人:layout_width =FILL_PARENT
机器人:layout_below =@ ID /条
机器人:layout_height =WRAP_CONTENT
机器人:启用=真
机器人:可点击=真
机器人:apiKey =0egkyrbiooKAfYyj43YB6wW1cmlG,TiIILXjpBg
/>
< / RelativeLayout的>
这是错误我得到张贴在我的logcat:
在android.view.ViewRoot.checkThread(ViewRoot.java:2683)
在android.view.ViewRoot.requestLayout(ViewRoot.java:557)
在android.view.View.requestLayout(View.java:7918)
在android.view.View.requestLayout(View.java:7918)
在android.view.View.requestLayout(View.java:7918)
在android.view.View.requestLayout(View.java:7918)
android.widget.RelativeLayout.requestLayout(RelativeLayout.java:255)
在android.view.View.requestLayout(View.java:7918
在android.view.View.requestLayout(View.java:7918)
在android.widget.TextView.checkForRelayout(TextView.java:5380)
在android.widget.TextView.setText(TextView.java:2684)
在android.widget.TextView.setText(TextView.java:2552)
在
android.widget.TextView.setText(TextView.java:2527)
在com.Server_1.Server4 $ InitTask.doInBackground(Server4.java:86)
在com.Server_1.Server4 $ InitTask.doInBackground(Server4.java:1)
在此我得到thie错误行是:
speed_1.setText(Integer.toString(速度));
解决方案
您应该总是张贴在UIThread UI更新。
runOnUiThread(新的Runnable(){
公共无效的run(){
speed_1.setText(Integer.toString(速度));
location.setText(LOC1);
}
}
I'm reading some data like speed and curent location using a single ton class....I'm reading them using an AsyncTask thread in a loop....:)....each time I'm reading a new speed and location I'm setting them in a text view above a map.
This is how a part of my code looks like:
while (true) {
speed = ServerManager.getInstance().getLastSpeed();
loc1 = ServerManager.getInstance().getLastLocation();
speed = ServerManager.getInstance().getLastSpeed();
speed_1.setText(Integer.toString(speed));
location.setText(loc1);
}
where:
speed-is float and loc1-is String.This is how my xml looks like:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:id="@+id/bar"
android:background="#FFFFFF"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/prod1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:textSize="12px"
android:text="Current Location"
/>
<TextView
android:id="@+id/location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:textColor="#013220"
android:textSize="12px"
/>
<TextView
android:id="@+id/prod2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingLeft="90dip"
android:textSize="12px"
android:text="Speed"
/>
<TextView
android:id="@+id/speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:textColor="#013220"
android:textSize="12px"
/>
</LinearLayout>
<com.google.android.maps.MapView
android:id="@+id/mapview1"
android:layout_width="fill_parent"
android:layout_below="@id/bar"
android:layout_height="wrap_content"
android:enabled="true"
android:clickable="true"
android:apiKey="0egkyrbiooKAfYyj43YB6wW1cmlG-TiIILXjpBg"
/>
</RelativeLayout>
And this is the error I get posted in my logcat:
at android.view.ViewRoot.checkThread(ViewRoot.java:2683)
at android.view.ViewRoot.requestLayout(ViewRoot.java:557)
at android.view.View.requestLayout(View.java:7918)
at android.view.View.requestLayout(View.java:7918)
at android.view.View.requestLayout(View.java:7918)
at android.view.View.requestLayout(View.java:7918)
android.widget.RelativeLayout.requestLayout(RelativeLayout.java:255)
at android.view.View.requestLayout(View.java:7918
at android.view.View.requestLayout(View.java:7918)
at android.widget.TextView.checkForRelayout(TextView.java:5380)
at android.widget.TextView.setText(TextView.java:2684)
at android.widget.TextView.setText(TextView.java:2552)
at
android.widget.TextView.setText(TextView.java:2527)
at com.Server_1.Server4$InitTask.doInBackground(Server4.java:86)
at com.Server_1.Server4$InitTask.doInBackground(Server4.java:1)
The line at which I get thie error is:
speed_1.setText(Integer.toString(speed));
解决方案
You should always post UI updates on the UIThread.
runOnUiThread(new Runnable() {
public void run() {
speed_1.setText(Integer.toString(speed));
location.setText(loc1);
}
}
上一篇:集成Unity3d查看到Android的活动Unity3d、Android
下一篇:RESTful服务回报 - 有一个错误检查[]类型System.Byte对象的起始单元。遇到意外的字符“Y”有一个、字符、单元、对象