If-else working, switch not

后端 未结 9 1837
一向
一向 2020-12-03 14:44

I am making an app that has a grid of images with text and each one opens a different activity. It works fine but just for design purposes I want to replace my if-else

9条回答
  •  悲哀的现实
    2020-12-03 15:28

    The switch needs a break with in each case. But in your case it could be done much simpler by defining an array as shown below.

    String values = {R.string.zero, R.string.one, R.string.two, ... };
    

    Use this to populate textView : textView.setText(values[position]);

提交回复
热议问题