2016-10-24 8 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行目で設定された)レンジャリング可能なものだけが表示されます。他のどれも。なぜ誰が知っている? Iveは色を変えようとしましたが、助けがありませんでした。

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

+0

!beacons.empty()条件が満たされていない場合に備えて、beacons.size()を記録しようとしましたか? –

答えて

0

は、レンジラベルが画面の中央にセンタリングされるようになっています。私のコードに必要な場合

とそこに間違って何かを推測、これは私のXMLです。 おそらく他のラベルをカバーしている可能性があります。

他のラベルが表示されているかどうかを確認してください。 と私はあなたが達成しようとしているか分からない。相対的なものではなく、LinearLayoutを使うことができます。

関連する問題