Android TextView setText覆盖上一个文本

Android TextView setText覆盖上一个文本,android,textview,settext,Android,Textview,Settext,我想在我的应用程序(应用程序)的文本视图中设置文本。这是我使用的代码: TextView lonTextView = (TextView) findViewById(R.id.textViewLonWert); lonTextView.setText(longitude.toString()); 实际上它可以工作,但仍显示上一个文本!例如,4覆盖了8(您无法再阅读文本) 我有一项开始服务的活动。然后将LocalBroadcastReceiver注册到活动。服务定期向活动发送位置对象。从我得到的

我想在我的应用程序(应用程序)的文本视图中设置文本。这是我使用的代码:

TextView lonTextView = (TextView) findViewById(R.id.textViewLonWert);
lonTextView.setText(longitude.toString());
实际上它可以工作,但仍显示上一个文本!例如,4覆盖了8(您无法再阅读文本)

我有一项开始服务的活动。然后将LocalBroadcastReceiver注册到活动。服务定期向活动发送位置对象。从我得到的位置,例如经度,我想用新的经度更新textview(只包含经度)

如果有人有办法解决这个问题,我会非常高兴

更新: 完整代码相当长,因此以下是相关片段:

TrackingActivity.java

public class TrackingActivity extends Activity {

// GPSTracker class
GPSTracker gps; 

public String filename;

/* Um eigene Position anzuzeigen */
ArrayList<OverlayItem> overlayItemArray;
protected MapView mapView;
protected MapController mapController;
public Boolean isPause;
public Boolean isTracking;
public MyLocationOverlay myLocationOverlay;
PathOverlay myPath;
List<GeoPoint> path;

public BroadcastReceiver screenReceiver;

/* Textviews setzen */
TextView lonTextView;
TextView latTextView;
TextView altTextView;
TextView accTextView;

// Initiating Menu XML file (menu.xml)
/*@Override
public boolean onCreateOptionsMenu(Menu menu)
{

    MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.menu.menu_tracking, menu);
    MenuItem mi_startTracking = menu.findItem(R.id.start_tracking);
    mi_startTracking.setVisible(true);
    return true;
}*/

/**
 * Event Handling for Individual menu item selected
 * Identify single menu item by it's id
 * */
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
    ...
}    

@Override

public boolean onPrepareOptionsMenu(Menu menu) {
   ...
}

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

    isTracking  = false;
    isPause     = false;

    // create GPS-class object
    gps = new GPSTracker(TrackingActivity.this
                        ,null);

    myPath  = new PathOverlay(Color.RED, this);
    path    = new ArrayList<GeoPoint>();

   /* Map anzeigen */
    mapView = new MapView(this, 500);
    mapView.setTileSource(TileSourceFactory.MAPNIK);
    org.osmdroid.views.MapView.LayoutParams mapParams = new                   org.osmdroid.views.MapView.LayoutParams(
            org.osmdroid.views.MapView.LayoutParams.MATCH_PARENT,
            org.osmdroid.views.MapView.LayoutParams.MATCH_PARENT,
            null, 0, 0, 0);
    /*löst Fehler aus: mapView.setClickable(true);*/
    mapView.setBuiltInZoomControls(true);
    mapController = new MapController(mapView);
    mapView.getController().setZoom(15);


    //--- Create Overlay
    overlayItemArray = new ArrayList<OverlayItem>();

    DefaultResourceProxyImpl defaultResourceProxyImpl   = new DefaultResourceProxyImpl(this);
    MyItemizedIconOverlay myItemizedIconOverlay         = new MyItemizedIconOverlay(
                                                        overlayItemArray, null, defaultResourceProxyImpl);
    mapView.getOverlays().add(myItemizedIconOverlay);
    //---

    //Add current position
    myLocationOverlay = new MyLocationOverlay(this, mapView);
    mapView.getOverlays().add(myLocationOverlay);

    /* Lege Pfad auf Karte */
    mapView.getOverlays().add(myPath);
    mapView.invalidate();
    LinearLayout myLayout = (LinearLayout) findViewById(R.id.trackingLinearLayoutMap);

    myLayout.addView(mapView,mapParams);

}

private BroadcastReceiver gpsDataReceiver = new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {

        //Log.d("TrackingActivity", "in Receiver");
        /* alles was der Service liefert */
        String action       = intent.getAction();
        Double altitude     = intent.getDoubleExtra("altitude", 0);
        Double longitude    = intent.getDoubleExtra("longitude", 0);
        Double latitude     = intent.getDoubleExtra("latitude", 0);
        Bundle b            = intent.getExtras();
        Location location   = (Location)b.get("location");

        Log.d("received","Receiver: "+longitude+" ; "+latitude);


        //Log.d("TrackingActivity", "vor GeoPoint");
        GeoPoint locGeoPoint = new GeoPoint(latitude, longitude);

                /* Erstelle Pfad */
        if(isTracking){
            path.add(locGeoPoint);
            myPath.addPoint(locGeoPoint);
        }
        //Log.d("TrackingActivity", "nach GeoPoint: "+locGeoPoint.toString());
        mapController.setCenter(locGeoPoint);

        setOverlayLoc(location);

        /* Textviews Werte setzen */
        lonTextView = (TextView) findViewById(R.id.textViewLonWert);
        lonTextView.setText(longitude.toString());
        //lonTextView.invalidate();

        latTextView = (TextView) findViewById(R.id.textViewLatWert);
        latTextView.setText(latitude.toString());
        //latTextView.invalidate();

        altTextView = (TextView) findViewById(R.id.textViewAltWert);
        altTextView.setText(altitude.toString());
        //altTextView.invalidate();

        accTextView = (TextView) findViewById(R.id.textViewAccWert);
        accTextView.setText(Float.toString(location.getAccuracy())+" m");
        //accTextView.invalidate();

        /* Karte aktualisieren */
        mapView.invalidate();

    }
};
...
@Override
protected void onResume() {
    super.onResume();
    /* Registriere BroadcastReceiver für GPSDaten */
    LocalBroadcastManager.getInstance(this).registerReceiver(gpsDataReceiver, new IntentFilter("gpsdata"));

        ...

}
...
公共类跟踪活动扩展活动{
//GPSTracker类
全球定位系统;
公共字符串文件名;
/*本征位置*/
ArrayList overlayItemArray;
受保护的地图视图;
受保护的映射控制器映射控制器;
公共事业;
公共布尔跟踪;
公共我的位置overlay我的位置overlay;
病理性胃溃疡;
列表路径;
公共广播接收机;
/*文本视图设置*/
文本视图lonTextView;
TextView latTextView;
文本视图altTextView;
文本视图accTextView;
//启动菜单XML文件(Menu.XML)
/*@凌驾
公共布尔onCreateOptions菜单(菜单)
{
MenuInflater MenuInflater=getMenuInflater();
菜单充气(R.menu.menu\U跟踪,菜单);
MenuItem mi_startTracking=menu.findItem(R.id.start_tracking);
mi_startTracking.setVisible(真);
返回true;
}*/
/**
*所选单个菜单项的事件处理
*通过单个菜单项的id标识该菜单项
* */
@凌驾
公共布尔值onOptionsItemSelected(菜单项项)
{
...
}    
@凌驾
公共布尔值OnPrepareOptions菜单(菜单){
...
}
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u跟踪);
isTracking=false;
isPause=false;
//创建GPS类对象
gps=新的GP斯特拉克(TrackingActivity.this
,空);
myPath=newpathoverlay(Color.RED,this);
路径=新的ArrayList();
/*地图特征*/
mapView=新mapView(此,500);
setTileSource(TileSourceFactory.MAPNIK);
org.osmdroid.views.MapView.LayoutParams mapParams=新建org.osmdroid.views.MapView.LayoutParams(
org.osmdroid.views.MapView.LayoutParams.MATCH_父级,
org.osmdroid.views.MapView.LayoutParams.MATCH_父级,
null,0,0,0);
/*löst Fehler aus:mapView.setClickable(真)*/
mapView.SetBuilTinZoomControl(真);
mapController=新的mapController(mapView);
mapView.getController().setZoom(15);
//---创建覆盖
overlayItemArray=新的ArrayList();
DefaultResourceProxyImpl DefaultResourceProxyImpl=新的DefaultResourceProxyImpl(此);
MyItemIzedEdiconOverlay MyItemIzedEdiconOverlay=新建MyItemIzedEdiconOverlay(
overlayItemArray,null,defaultResourceProxyImpl);
mapView.getOverlays().add(MyItemIzedEdiconOverlay);
//---
//添加当前位置
myLocationOverlay=新建myLocationOverlay(此为地图视图);
mapView.getOverlays().add(myLocationOverlay);
/*卡丁车法*/
mapView.getOverlays().add(myPath);
mapView.invalidate();
LinearLayout myLayout=(LinearLayout)findViewById(R.id.trackingLinearLayoutMap);
addView(mapView,mapParams);
}
专用广播接收器gpsDataReceiver=新广播接收器(){
@凌驾
公共void onReceive(上下文、意图){
//Log.d(“跟踪活动”,“接收器中”);
/*阿列斯是为利弗特服务的*/
String action=intent.getAction();
双高度=意图。getDoubleExtra(“高度”,0);
双经度=intent.getDoubleExtra(“经度”,0);
双纬度=intent.getDoubleExtra(“纬度”,0);
Bundle b=intent.getExtras();
位置=(位置)b.get(“位置”);
Log.d(“接收”,“接收器:+经度+”;“+纬度”);
//Log.d(“跟踪活动”、“vor检波器”);
地理点位置地理点=新的地理点(纬度、经度);
/*厄斯泰尔Pfad*/
如果(正在跟踪){
添加路径(本地点);
myPath.addPoint(本地点);
}
//Log.d(“TrackingActivity”,“nach GeoPoint:+Locageopoint.toString());
地图控制器。设置中心(本地点);
setyloc(位置);
/*Textviews Werte setzen*/
lonTextView=(TextView)findViewById(R.id.textViewLonWert);
lonTextView.setText(经度.toString());
//lonTextView.invalidate();
latTextView=(TextView)findViewById(R.id.textViewLatWert);
latTextView.setText(latitude.toString());
//latTextView.invalidate();
altTextView=(TextView)findViewById(R.id.textViewAltWert);
altTextView.setText(altitude.toString());
//altTextView.invalidate();
accTextView=(TextView)findViewById(R.id.textViewAccWert);
accTextView.setText(Float.toString(location.getAccuracy())+“m”);
//accTextView.invalidate();
/*卡特尔阿克图阿利塞伦酒店*/
mapView.invalidate();
}
};
...
@凌驾
受保护的void onResume(){
super.onResume();
/*注册广播接收机für GPSDaten*/
LocalBroadcastManager.getInstance(this.registerReceiver(gpsDataReceiver,新的意向过滤器(“gpsdata”));
...
}
...
这里是my layout.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/trackingLinearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<LinearLayout
    android:id="@+id/trackingStatusOuterWrapper"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="kein GPS Signal"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textSize="10sp" />

    <LinearLayout
    android:id="@+id/trackingStautsInnerWrapper2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
        <TextView
        android:id="@+id/textViewLonLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Länge: "
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textSize="10sp" />
        <TextView
        android:id="@+id/textViewLonWert"
        android:layout_width="80dp"
        android:layout_height="wrap_content"
        android:text=""
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textSize="10sp" />
        <TextView
        android:id="@+id/textViewLatLabel"
        android:layout_marginLeft="40dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Breite: "
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textSize="10sp" />
        <TextView
        android:id="@+id/textViewLatWert"
        android:layout_width="80dp"
        android:layout_height="wrap_content"
        android:text=""
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textSize="10sp" />

    </LinearLayout>
    <LinearLayout
    android:id="@+id/trackingStautsInnerWrapper3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

        <TextView
        android:id="@+id/textViewAltLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Höhe: "
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textSize="10sp" />
        <TextView
        android:id="@+id/textViewAltWert"
        android:layout_width="80dp"
        android:layout_height="wrap_content"
        android:text=""
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textSize="10sp" />
        <TextView
        android:id="@+id/textViewAccLabel"
        android:layout_marginLeft="40dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Genauigkeit: "
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textSize="10sp" />
        <TextView
        android:id="@+id/textViewAccWert"
        android:layout_width="80dp"
        android:layout_height="wrap_content"
        android:text=""
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textSize="10sp" />
    </LinearLayout>
</LinearLayout>
<!--  
<org.osmdroid.views.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:clickable="true"/>
-->

<LinearLayout
    android:id="@+id/trackingLinearLayoutMap"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

</LinearLayout>


希望能有帮助!

你永远不会相信这一点,但如果你去那里,你会发现一个问题和答案,我想这是可以解决的
<resources>
    <color name="black">#ff000000</color>
</resources>
    android:background="@color/black"
    <TextView
    android:id="@+id/textViewLonWert"
    android:layout_width="80dp"
    android:layout_height="wrap_content"
    android:text=""
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:textSize="10sp" />