2016-04-01 13 views
0

Ich versuche, ein XML-Array aus einer Ressource-Datei dynamisch abrufen, aber ich bekomme Exception-Nummer Fehler.dynamisch erstellen Ressourcen-IDs Android

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); 

Antwort

1

Ich denke, man sollte so etwas wie dieses

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

tun, wenn Sie die Ressource-ID für R.array.c<key> erhalten möchten.

+0

Danke für Ihre Hilfe! – user2552828