我正在尝试在列表视图中显示文件:
完美无缺。现在我正在尝试将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);
它只显示一个textview。为什么呢?
答案 0 :(得分:0)
ListView
只接受一个Adapter
。您的上一个代码行会将ListView
适配器从mAdapterSecond
更改为mAdapter
。在您的情况下,您需要实现自定义适配器,根据需要填充两个TextView
。