2016-10-24 128 views
0

我正面臨一個問題。運行應用程序後,我設置的文本視圖不會顯示。這是我的代碼:android textview settext不顯示

protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_main); 

final TextView rangeLabel = (TextView) findViewById(R.id.range_label); 
final TextView beaconMacAddressLabel = (TextView) findViewById(R.id.beacon_mac_address_label); 
final TextView beaconUuidLabel = (TextView) findViewById(R.id.beacon_uuid_label); 
final TextView beaconVersionLabel = (TextView) findViewById(R.id.beacon_major_minor_label); 
final TextView beaconStatsLabel = (TextView) findViewById(R.id.beacon_stats_label); 

rangeLabel.setTextColor(Color.BLACK); 
rangeLabel.setText(R.string.question_mark); 
region = new Region("regionid", null, null, null); 

beaconManager = new BeaconManager(this); 
beaconManager.setRangingListener(new RangingListener() { 
    @Override 
    public void onBeaconsDiscovered(Region region, final List<Beacon> beacons) { 
     runOnUiThread(new Runnable() { 

       @Override 
       public void run() { 
        if (!beacons.isEmpty()) { 

         Beacon closestBeacon = beacons.get(0); 

         beaconMacAddressLabel.setText(getString(R.string.mac_address) + " : " + closestBeacon.getMacAddress()); 
         beaconUuidLabel.setText(closestBeacon.getProximityUUID()); 
         beaconVersionLabel.setText(getString(R.string.major) + ": "+closestBeacon.getMajor() + 
               " " + getString(R.string.minor) + ": " + closestBeacon.getMinor()); 

         beaconStatsLabel.setText(getString(R.string.power) + ": " + 
              closestBeacon.getMeasuredPower() + 
              " " + 
              getString(R.string.dbm) + 
              " | " + 
              getString(R.string.rssi) + 
              ": " + closestBeacon.getRssi()); 

         double accuracy = Utils.computeAccuracy(closestBeacon); 

         switch (Utils.proximityFromAccuracy(accuracy)) { 
         case FAR: 
          rangeLabel.setText(R.string.cold); 
          rangeLabel.setTextColor(getResources().getColor(R.color.cold_colour)); 
          rangeLabel.setBackgroundResource(R.drawable.cold_indicator_background); 
          break; 
         case NEAR: 
          rangeLabel.setText(R.string.warm); 
          rangeLabel.setTextColor(getResources().getColor(R.color.warm_colour)); 
          rangeLabel.setBackgroundResource(R.drawable.warm_indicator_background); 
          break; 
         case IMMEDIATE: 
          rangeLabel.setText(R.string.hot); 
          rangeLabel.setTextColor(getResources().getColor(R.color.hot_colour)); 
          rangeLabel.setBackgroundResource(R.drawable.hot_indicator_background); 
          break; 
         case UNKNOWN: 
          rangeLabel.setText(R.string.question_mark); 
          rangeLabel.setTextColor(Color.BLACK); 
          rangeLabel.setBackgroundResource(R.drawable.indicator_background); 
          break; 

mycode有什麼問題嗎?只顯示標題(以XML設置)和可分區(在第10行設置)。沒有其他。有誰知道爲什麼? 我試圖改變顏色,但沒有幫助。猜猜有什麼錯我的代碼

在需要的情況下

,這是我的XML:

https://github.com/KarlNosworthy/hotwarmcold/blob/master/HotWarmColdApp/src/main/res/layout/activity_main.xml

+0

如果沒有滿足!beacons.empty()條件,是否嘗試記錄beacons.size()? –

回答

0

貌似範圍標籤在屏幕的中間居中。 它可能覆蓋其他標籤

試着隱藏它,看看你是否看到其他標籤。 ,我不確定你想要完成什麼。但您可能想要使用LinearLayout而不是相對...