我无法将数据从Activity(主)传递到Fragment(第一)。
在Main中,我要在First中声明一个变量为STATIC。我注意到,当我想显示变量数组时,它只显示索引为0。而,当索引不是0时,它将显示异常。
public static String tps = ""; //declare it on top in Main.
final String[] populateTPS = new String[1]; //it will save in 1 element of array`
populateTPS[0] = part3[2]; //populateTPS[0] because when i want to make populate [] it will give an error.
tps=populateTPS[0]; //this is in Main and In First, I will use the static variable tps
但是当我想显示此字符串数组的特定索引时,它将无法正常工作。
这是因为片段问题吗?因为当我在“活动”中尝试时,它会起作用。
// IN活动
` final String[] populateRPM = new String[2]; // length is 2.
populateRPM[0] =(part3[3]);
String []populateRpmData= populateRPM[0].split(" ");
pr.setText( populateRpmData[3]);//it works