2015-01-21 2 views
0

페이지를 길게 누르면 색 구성표가 응용 프로그램의 모든 페이지에서 흑백으로 변경되는 함수를 작성하려고합니다. 페이지 또는 다른 페이지를 길게 클릭하면 변경 사항이 되돌려 야합니다. 여기에 제가 가지고있는 견본이 있습니다. 보다 구체적인 코드를보고 싶다면 알려주십시오.다른보기를 올바르게 액세스하고 변경하는 방법

View sigView; 
View rootView; 
View tunerView; 
public boolean pm; 
public SharedPreferences sharedPreferences; 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 

    sigView = inflater.inflate(R.layout.time_sig, container,false); 
    rootView=inflater.inflate(R.layout.activity_metronome,container); 
    tunerView=inflater.inflate(R.layout.activity_tuner,container); 

    final TextView tvTempo=(TextView) rootView.findViewById(R.id.metro_disp); 
    final TextView NumView = (TextView) sigView.findViewById(R.id.Sig_Num); 
    final TextView tv_note=(TextView) tunerView.findViewById(R.id.tv_note);   
    final ImageView time_sig_bar= ImageView)sigView.findViewById(R.id.time_sig_bar); 

    //**Lots more lines just like above for other elements 

time_sig_bar.setOnLongClickListener(new View.OnLongClickListener() { 
     @Override 
     public boolean onLongClick(View view) { 
      if (!pm) { 
       rootView.setBackgroundColor(Color.BLACK); 
       //**Code to run 

       pm=true; 
       sharedPreferences.edit().putBoolean("pm",pm).apply(); 
      } else{ 
       rootView.setBackgroundColor(Color.TRANSPARENT); 
      //**More code to run 

       pm=false; 
       sharedPreferences.edit().putBoolean("pm",pm).apply(); 
      } 
//**code is copied for other elements to respond to longclick 

이 코드를 복사하여 다른 페이지에 붙여 넣었습니다 (몇 가지 작은 변경 사항이 있음). 다른 페이지 중 하나에서 해당 페이지의 요소가 변경되지만 다른 페이지의 요소는 변경되지 않습니다. 또한 색상을 다른 페이지에서 다시 변경하도록 설정하는 방법을 모르겠습니다. 내가 뭘 잘못하고 있는거야? 도와 주셔서 감사합니다.

답변

0

에는보기에 대한 상태 데이터를 보유하는 새 클래스가있을 수 있습니다. longclicked 인 경우는 true, 그렇지 않은 경우는 false 그러면 현재 상태가 아닌 상태로 longlick 상태를 설정할 수 있습니다.

관련 문제