2016-06-26 1 views
0

Estimote 비콘을 사용하는 응용 프로그램을 개발 중이며 클래스 내에서 사용해야하는 변수와 관련하여 문제가 있습니다.
제 경우에는 실제 비컨과 이전 비컨을 유지하고 그들이 인접 매트릭스에있는 이웃인지 비교해야합니다.
문제는 내가 비컨 스캐너 작동 중에 수정할 수 없다고 선언 한 것처럼 이전 비컨에 대해 이것을 가능하게 할 수 없다는 것입니다. 내가 그것을 최종적으로 만들지 않으면 안드로이드 스튜디오는 내면 수업에서 그것을 사용할 수 없게된다. 이 문제에 대한 해결책이 있습니까?final을 선언하지 않고 내부 클래스에서 변수를 사용하는 방법

코드 :

beaconManager = new BeaconManager(this); 
     beaconManager.setBackgroundScanPeriod(1000,3000); 
     int previousBeaconInMatrix = 0; 


     beaconManager.setRangingListener(new BeaconManager.RangingListener() { 





      public void onBeaconsDiscovered(Region region, List<Beacon> list) { 
       if (!list.isEmpty()) 
       { 

        Animation animate = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.test); 

        int sizeOfList = list.size(); 


         int actualBeacon = findMyposition(list.get(0)); 



         if(adjacencyMatrix[actualBeacon][previousBeacon] == 1) { 
         if (beaconTable.containsKey(number)) { 


          List<Integer> coordinates = new ArrayList<Integer>(2); 
          coordinates = beaconTable.get(number); 
          View myPosition = ButtonTable.get(coordinates); 
         blueButton.clearAnimation(); 
         blueButton2.clearAnimation(); 
         yellowButton.clearAnimation(); 
         orangeButton.clearAnimation(); 
         orangeButton2.clearAnimation(); 
         purpleButton.clearAnimation(); 
         redButton.clearAnimation(); 
         greenButton.clearAnimation(); 
          myPosition.startAnimation(animate); 
         } 

         } 


       previousBeacon = actualBeacon ; 

    } 
    } 
     }); 
    region = new Region("ranged region", null, null, null); 
} 
+1

당신이 말하는 변수는'previousBeaconInMatrix'입니까? 그리고 문제의 내부 클래스는'new BeaconManager.RangingListener()'입니까? 마지막으로,이 코드가있는 클래스의 이름은 무엇입니까? 가장 쉬운 방법은'BeaconManager.RangingListener'를 구현하도록 클래스를 만들고 나서 그 클래스의'onBeaconsDiscovered' 메소드에서'previousBeaconInMatrix'에 접근하는 것입니다. – ishmaelMakitla

+0

BeaconManager.RangingListener를 확장하여 변경할 필드를 추가 할 수 있습니다 –

답변

0

외부 클래스의 private 특성에 변수에서 이동하는 것입니다 내부 클래스를 통해 그 값을 변경하는 변수를 사용하는 가장 쉬운 방법.

관련 문제