请问:ViewPager下的View增加ListView是否直接就只要将View当成一个布局文件照样弄就行了
这是ListView的主类,运行后在这个View页面是空的,不知道什么原因?
谢谢!!
package com.example.plant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class ViewFirst extends Activity{
private ListView listView;
private SimpleAdapter simAdapter;
private List<Map<String,Object>>dataList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view1);
//初始化控件
listView=(ListView) findViewById(R.id.listView1);
dataList=new ArrayList<Map<String,Object>>();
simAdapter=new SimpleAdapter(this, getData(), R.layout.item1,
new String[]{"imageView1","textView1"},
new int[]{R.id.imageView1,R.id.textView1});
//加载适配器
listView.setAdapter(simAdapter);
}
//获取数据源的方法
private List<Map<String,Object>> getData() {
for(int i=0;i<20;i++){
Map<String,Object>map=new HashMap<String,Object>();
map.put("imageView1", R.drawable.ic_launcher);
map.put("textView1", "花卉");
dataList.add(map);
}
return dataList;
}
}