2016-04-01 17 views
0

私はリソースファイルから動的にXML配列を取得しようとしていますが、例外番号エラーが発生し続けます。動的にリソースIDを作成する

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
      View rootView = inflater.inflate(R.layout.fragment_class, container, false); 
      TextView classTitle = (TextView) rootView.findViewById(R.id.class_title); 
      classTitle.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER))); 

      //FETCH THE XML ARRAY 
      String[] classAvgArray = getResources().getStringArray(R.array.classAvg); 
      //INDEX OF THE ARRAY 
      int key = getArguments().getInt(ARG_SECTION_NUMBER); 

      //DISPLAY THE AVG AMOUNT 
      TextView classTextAverage = (TextView) rootView.findViewById(R.id.classAvgAmount); 
      classTextAverage.setText("Avg: "+classAvgArray[key]); 

      //FETCH THE XML ARRAY FOR ITEMS 
      String ID = "c"+key; 

      int resID = getResources().getIdentifier(ID, "R.array.c"+key, "za.co.infomycito.mycitoapp"); 

      String[] classactivities = getResources().getStringArray(resID); 

答えて

1

私はあなたがR.array.c<key>のためのリソースIDを取得したい場合は、この

int resID = getResources().getIdentifier("c"+key, "array", getPackageName()); 

ようなことをやるべきだと思います。

+0

ありがとうございました! – user2552828

関連する問題