I have a question regarding performance and best approach for my Android code.
What I need to do is fairly simple, I want to dynamically assign a text value to a string ressource, depending on a int parameter:
For now I am using a big switch case
int messagesCategory;
if(extras !=null) {
messagesCategory = extras.getInt("category");
}
TextView titleText;
titleText = (TextView) findViewById(R.id.headerTitle);
switch (messagesCategory) {
case 1: titleText.setText(R.string.TitleMessageList1); break;
case 2: titleText.setText(R.string.TitleMessageList2); break;
case 3: titleText.setText(R.string.TitleMessageList3); break;
case 4: titleText.setText(R.string.TitleMessageList4); break;
case ...: titleText.setText(R.string.TitleMessageList...); break;
case n: titleText.setText(R.string.TitleMessageListn); break;
default: titleText.setText("a default title"); break;
}
Let's say I have 30 lines in this switch... It works but for many cases, it looks there is a better way to achieve this. Unfortunately it does not look possible to assign something dynamic to R.string..
So my first question is: 1) performance wise, in this case, is it a problem to use a big switch for 30 cases or so? 2) what should be the best approach?
Thanks and have a good day