我正在尝试在列表视图中显示文件:
它完美地工作。现在我正在尝试将 TextView 添加到此 Listview 中,所以我尝试了以下操作:我不想使用适配器类。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv =(TextView) findViewById(R.id.textView2);
path = Environment.getExternalStorageDirectory().getPath();
file = new File(path);
setListView();
}
public void setListView(){
String[] mFilesList = file.list();
mListView = (ListView)findViewById(R.id.listView1);
mArray = new ArrayList<String>();
fArray = new ArrayList<String>();
for(int i = 0; i<mFilesList.length; i++){
mArray.add(mFilesList[i]);
}
for (int i = 0; i < mFilesList.length; i++) {
fArray.add(mFilesList[i].length()+" files");
}
ArrayAdapter<String> mAdapter = new ArrayAdapter<String>(getApplicationContext()
, R.layout.rows, R.id.textView1,mArray);
ArrayAdapter<String> mAdapterSecond = new ArrayAdapter<String>(getApplicationContext()
, R.layout.rows, R.id.textView2,fArray);`
mListView.setAdapter(mAdapterSecond);
mListView.setAdapter(mAdapter);
它只显示一个文本视图。为什么?