在这里,我逐字阅读文件并使用这些单词操作列表视图。这里的问题是名字和姓氏出现在不同的行中。例如 Name = "John Clerk" 然后我在列表视图的第一行中得到“John”,在第二行中得到“Clerk”。对于其他数据,它们必须在单行中,依此类推。我应该做些什么改变才能正常工作?我的代码...
String myData = "";
String strLine;
String listName = "" ;
FileOutputStream fos;
FileInputStream fstream;
DataInputStream in;
String[] SavedFiles;
BufferedReader br;
public void readFile(String file) throws IOException
{
fstream = openFileInput(file);
Scanner scanFile = new Scanner(new DataInputStream(fstream));
ArrayList<String> words = new ArrayList<String>();
String theWord, theWord1, theWord2;
while (scanFile.hasNext())
{
theWord = scanFile.next();
words.add(theWord);
}
Toast.makeText(getBaseContext(), "" + size, 1000).show();
adapterFriends = new ArrayAdapter<String>(getBaseContext(), R.layout.text, words);
lvFinal.setAdapter(adapterFriends);
adapterFriends.notifyDataSetChanged();
}