我正在尝试用我的文件数据填充列表视图。我在这里要做的是,我必须在一个活动中读取文件并将此文件数据传递到另一个活动的列表视图中。我已在第二个活动的列表视图中成功传递了这些数据,但数据显示在单行中。个别数据没有出现在个别行中......这是我的代码......
第一活动.java
String myData = "";
String strLine;
String listName = "" ;
FileOutputStream fos;
FileInputStream fstream;
DataInputStream in;
String[] SavedFiles;
BufferedReader br;
public void readFile(String file) throws IOException
{
try
{
fstream = openFileInput(file);
in = new DataInputStream(fstream);
br = new BufferedReader(new InputStreamReader(in));
while ((strLine=br.readLine()) != null)
{
myData +=(strLine);
mapList.add(strLine);
}
//FinalList.arrFriends = mapList;
in.close();
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
Intent in1 = new Intent(getBaseContext(), FinalList.class);
in1.putStringArrayListExtra("Data", mapList);
startActivity(in1);
}
SecondActivity.java
public class FinalList extends Activity{
ListView lvFinal;
ArrayAdapter<String> adapterFriends;
public static ArrayList<String> arrFriends = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.final_list);
lvFinal = (ListView)findViewById(R.id.list2);
Intent in = getIntent();
arrFriends = in.getStringArrayListExtra("Data");
adapterFriends = new ArrayAdapter<String>(getBaseContext(), R.layout.text, arrFriends);
lvFinal.setAdapter(adapterFriends);
adapterFriends.notifyDataSetChanged();
}
}
我错过了什么?这是输出的图像。