내 응용 프로그램에는 각각 자체적으로 상호 작용하는 두 개의 페이지 (조각)가 있습니다. 두 페이지 중 하나를 길게 클릭하면 색 구성표가 흑백과 다시 표시로 전환됩니다. 이는 어느 페이지에서나 호출되는 별도의 Java 클래스를 사용하여 수행됩니다. 두 번째 페이지에서 실행하면 완벽하게 작동하지만 첫 번째 페이지에서 실행하면 두 번째 페이지가 변경되지 않습니다.조각 내 요소를 올바르게 변경하는 방법
페이지 : 1 :
firstView = inflater.inflate(R.layout.page1, container, false);
secondView = inflater.inflate(R.layout.page2, container);
//A bunch of code and then....
element1.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
pm = sharedPreferences.getBoolean("pm", false);
if (pm) {
performance.PerfModeOff();
pm = false;
sharedPreferences.edit().putBoolean("pm", pm).apply();
} else {
performance.PerfModeOn(mContext);
pm = true;
sharedPreferences.edit().putBoolean("pm", pm).apply();
}
return true;
}
});
2 페이지 : 물론
public Performance(View firstView, View secondView,LayoutInflater inflater, ViewGroup container) {
mfirstView = inflater.inflate(R.layout.page1, container,false);
msecondView = inflater.inflate(R.layout.page2, container,true);
uparrow= (ImageView) firstView.findViewById(R.id.UpArrow);
//**A lot of lines like above
public void PerfModeOn(Context context) {
mfirstView.setBackgroundColor(Color.BLACK);
msecondView.setBackgroundColor(Color.BLACK);
uparrow.setBackgroundTintList(ColorStateList.valueOf(context.getResources().getColor(R.color.DarkTint)));
//** More lines to change colors
public void PerfModeOff() {
//**Lines to change colors back
: 색상을 변경하는 것
secondView= inflater.inflate(R.layout.page2, container, false);
firstView = inflater.inflate(R.layout.page1, container);
//A bunch of code and then...
element2.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
pm = sharedPreferences.getBoolean("pm", false);
if (pm) {
performance.PerfModeOff();
pm = false;
sharedPreferences.edit().putBoolean("pm", pm).apply();
} else {
performance.PerfModeOn(mContext);
pm = true;
sharedPreferences.edit().putBoolean("pm", pm).apply();
}
return true;
}
});
클래스 여기에 길이 단순화 내 코드의 일부입니다 더 많은 코드가 필요하면 알려주세요. 이 문제를 해결하려면 어떻게해야합니까? 당신의 도움을 주셔서 감사합니다!
내가 inflaters를 사용하지 않고 PerfModeOn 및 PerfModeOff에서 내보기를 인수로 제공하면 제안한 것과 같은 문제가 발생합니다. 첫 번째 페이지는 여전히 두 번째 페이지의 텍스트 나 이미지를 변경하지 않습니다. LongClick이라는 페이지의 순서에 따라 너무 많은 이상한 행동이 있습니다. 다른 생각? –