我已经声明了一个“ Pair(List(String)), (List(String))
”来接收从一个方法返回的数据。但是我无法检索这两个单独的列表,因为它错误地说“ The method second() is undefined for the type Pair
”
这是我的代码:
public class EditPeople_ListFragment extends ListFragment {
public Pair<List<String>, List<String>> ReadPeopleFile(FileReader peopleReader){
///Soon parsed into a string list, by delimiting and separating into two string arrays,
char characterList[] = new char[10000]; // I'm assuming that 1000 is enough here
int numChars = 0;
try {
numChars = peopleReader.read(characterList);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String parseString = new String(characterList, 0, numChars);///Creates a string parseString.
List<String> parseString_array = new ArrayList<String>();///Initialises a list of strings
parseString_array = Arrays.asList(parseString.split(";"));///Splits the parseString into the parseString_array
List <String> mobileNumber = new ArrayList<String>();///Initialises a list of strings, meant to be mobile numbers.
List <String> name = new ArrayList<String>();///Initialises a list of string, meant to be names
String[] parts = new String[2];
for (String peopleDetails : parseString_array){///sets up a loop for each of the strings in parseString_array, to be split into mobile numbers, and name.
///delimiter: ";" is for each peopleDetail string. Delimiter: "," separates mobile number and names in each peopleDetails string.
parts = peopleDetails.split(",");
mobileNumber.add(parts[0]);
name.add(parts[1]);
}
try {
peopleReader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return new Pair(mobileNumber, name);
///Then use on return value nameList = ------.getname();
///and use --------.getmobileNumber();
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
FileReader peopleFile_Reader = new FileReader("PartyApp_PeopleFile");
Pair returnedpair = ReadPeopleFile(peopleFile_Reader);
List<String> mobileList = returnedpair.first();
List<String> nameList = returnedpair.second();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(inflater.getContext(), R.id.ListView_EditPeopleFragment, People_List);
setListAdapter(adapter);
return super.onCreateView(inflater, container, savedInstanceState);
}
}
谢谢您的帮助!!