У меня есть 12 кнопок, разделенных на 2 группы, в каждой по 6 кнопок, все кнопки реагируют на один длинный метод onClick goToCategory().
Я могу преобразовать его во множество небольших независимых методов onclick.
Моему приложению требуется слишком много времени для рендеринга изображений после нажатия/касания - около 2-3 секунд. Я запустил ddms, чтобы посмотреть, что происходит, сделал трассировку, и мое приложение натыкается на goToCategory() - по крайней мере, я думаю, что это основная проблема, вызывающая длительную задержку рендеринга. Я могу захотеть переписать длинный метод onclick.
Что лучше с точки зрения производительности?
public void goToCategory(View v){
switch (v.getId()){
case R.id.scientists:
categories.setVisibility(View.GONE);
hero1.setBackgroundResource(R.drawable.galim1);
hero2.setBackgroundResource(R.drawable.galim2);
hero3.setBackgroundResource(R.drawable.galim3);
upper_category_index = "science";
break ;
case R.id.scientists2:
categories2.setVisibility(View.GONE);
hero4.setBackgroundResource(R.drawable.galim1);
hero5.setBackgroundResource(R.drawable.galim2);
hero6.setBackgroundResource(R.drawable.galim3);
lower_category_index = "science";
break ;
case R.id.politics:
categories.setVisibility(View.GONE);
hero1.setBackgroundResource(R.drawable.pol1);
hero2.setBackgroundResource(R.drawable.pol2);
hero3.setBackgroundResource(R.drawable.pol3);
upper_category_index = "politics";
break ;
case R.id.politics2:
categories2.setVisibility(View.GONE);
hero4.setBackgroundResource(R.drawable.pol1);
hero5.setBackgroundResource(R.drawable.pol2);
hero6.setBackgroundResource(R.drawable.pol3);
lower_category_index = "politics";
break ;
case R.id.akins:
categories.setVisibility(View.GONE);
hero1.setBackgroundResource(R.drawable.akin1);
hero2.setBackgroundResource(R.drawable.akin2);
hero3.setBackgroundResource(R.drawable.akin3);
upper_category_index = "akin";
break ;
case R.id.akins2:
categories2.setVisibility(View.GONE);
hero4.setBackgroundResource(R.drawable.akin1);
hero5.setBackgroundResource(R.drawable.akin2);
hero6.setBackgroundResource(R.drawable.akin3);
lower_category_index = "akin";
break ;
case R.id.folk_heroes:
categories.setVisibility(View.GONE);
hero1.setBackgroundResource(R.drawable.folk1);
hero2.setBackgroundResource(R.drawable.folk2);
hero3.setBackgroundResource(R.drawable.folk3);
upper_category_index = "folk";
break ;
case R.id.folk_heroes2:
categories2.setVisibility(View.GONE);
hero4.setBackgroundResource(R.drawable.folk1);
hero5.setBackgroundResource(R.drawable.folk2);
hero6.setBackgroundResource(R.drawable.folk3);
lower_category_index = "folk";
break ;
case R.id.hans:
categories.setVisibility(View.GONE);
hero1.setBackgroundResource(R.drawable.han1);
hero2.setBackgroundResource(R.drawable.han2);
hero3.setBackgroundResource(R.drawable.han3);
upper_category_index = "hans";
break ;
case R.id.hans2:
categories2.setVisibility(View.GONE);
hero4.setBackgroundResource(R.drawable.han1);
hero5.setBackgroundResource(R.drawable.han2);
hero6.setBackgroundResource(R.drawable.han3);
lower_category_index = "hans";
break ;
case R.id.batirs:
categories.setVisibility(View.GONE);
hero1.setBackgroundResource(R.drawable.kabanbai);
hero2.setBackgroundResource(R.drawable.bogenbai);
hero3.setBackgroundResource(R.drawable.karasai);
upper_category_index = "batirs";
break ;
case R.id.batirs2:
categories2.setVisibility(View.GONE);
hero4.setBackgroundResource(R.drawable.kabanbai);
hero5.setBackgroundResource(R.drawable.bogenbai);
hero6.setBackgroundResource(R.drawable.karasai);
lower_category_index = "batirs";
break ;
}
}