【发布时间】:2015-09-27 03:32:33
【问题描述】:
最终目标是在不修改代码的情况下为程序添加额外的片段。我想通过更改资源文件的数组值(而不是在运行时)来做到这一点。一个资源数组具有微调器值,另一个具有片段文件名。它们在资源文件中列出的顺序是它们的关联方式:因此第一个微调器数组字符串与第一个片段 TypedArray 项相关,依此类推。
我编写了一个简单的类,以便我可以在我的微调器值和微调器值所代表的片段之间保持相关性。这是课程:
import android.support.v4.app.Fragment;
public class SensorList {
int index;
String name;
Fragment sensorFrag;
SensorList(){
name="";
sensorFrag=null;
index=0;
}
}
我想用资源 TypedList 中的值填充此类的一个实例。那就是我遇到问题的地方。到目前为止,这是我的代码。最后一行显然是错误的,因为它没有“添加”的索引。
public ArrayList<SensorList> sensorList = new ArrayList<SensorList>();
Resources res = getResources();
sensorList.(res.obtainTypedArray(R.array.sensor_frag_names)); //This line is a problem.
我是不是走错了路?有没有我可以申请的演员表。 如果这不清楚,请告诉我。谢谢。
【问题讨论】:
标签: android android-fragments arraylist