1

The ultimate goal is to add additional fragments to the program without modifying the code. I want to do this by changing the array-values of the resource files(not at run-time). One resource-array has the spinner values, another has the fragment file names. The order that they are listed in the resource file is how they correlate: So the first spinner array-String correlates to the first fragment TypedArray item and so on.

I wrote a simple class so that I can keep a correlation between my spinner values and the fragments that the spinner value represents. This is the class:

import android.support.v4.app.Fragment;
public class SensorList {
    int index;
    String name;
    Fragment sensorFrag;
    SensorList(){
        name="";
        sensorFrag=null;
        index=0;
    }
}

I want to populate an instance of this class with values from resource TypedList. That is where I am having problems. This is my code of that so far. The last line is clearly in error as it doesn't have an index for the 'add'.

public ArrayList<SensorList> sensorList = new ArrayList<SensorList>();
    Resources res = getResources();
    sensorList.(res.obtainTypedArray(R.array.sensor_frag_names));  //This line is a problem.

Am I going about this the wrong way? Is there a cast that I can apply. If this isn't clear, let me know. Thanks.

1 Answer 1

1
 Resources resources = getResources();
    TypedArray name= resources.obtainTypedArray(R.array.sensor_frag_names);
    TypedArray sensorFrag= resources.obtainTypedArray(R.array.sensor_frag_codes);
    TypedArray index= resources.obtainTypedArray(R.array.sensor_frag_index);

    SensorList slist= new SensorList (name.getString(index), sensorFrag.getFragment(index), index.getInt(index));

    name.recycle();
    sensorFrag.recycle();
    index.recycle();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.