首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

列表有关问题,不显示

2012-07-19 
列表问题,不显示模拟器出来什么也没有public class ListUser extends Activity {@Overrideprotected void

列表问题,不显示
模拟器出来什么也没有
public class ListUser extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.user);
ListView listv = (ListView) findViewById(R.id.ListView01); 

ArrayList<HashMap<String,String>> arrlist = new ArrayList<HashMap<String,String>>() ;
HashMap<String,String> map1 = new HashMap<String,String>();
HashMap<String,String> map2 = new HashMap<String,String>();
HashMap<String,String> map3 = new HashMap<String,String>();
map1.put("corpid", "001");
map1.put("corpname", "马祖");
map1.put("corpid", "002");
map1.put("corpname", "周二");
arrlist.add(map1);
arrlist.add(map2);
SimpleAdapter lia = new SimpleAdapter(this,  
  arrlist,  
  R.layout.usercol,  
  new String[] { "cpid", "cpname" },  
  new int[] { R.id.cpid, R.id.cpname });
listv.setAdapter(lia); 

}

}

user.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
android:orientation="horizontal">

<ListView android:layout_width="fill_parent"  
  android:layout_height="wrap_content"  
  android:id="@+id/ListView01"  
  /> 
</LinearLayout>

usercol.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
android:orientation="horizontal">
<TextView
  android:id="@+id/cpid"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:singleLine="true"
  />
<TextView
  android:id="@+id/cpname"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  />
</LinearLayout>

[解决办法]
map1.put("corpid", "001");
map1.put("corpname", "马祖");
map1.put("corpid", "002");
map1.put("corpname", "周二");
arrlist.add(map1);
arrlist.add(map2);
SimpleAdapter lia = new SimpleAdapter(this,
arrlist,
R.layout.usercol,
new String[] { "cpid", "cpname" },
new int[] { R.id.cpid, R.id.cpname });
listv.setAdapter(lia);

修改为
map1.put("corpid", "001");
map1.put("corpname", "马祖");
map2.put("corpid", "002");
map2.put("corpname", "周二");
arrlist.add(map1);
arrlist.add(map2);
SimpleAdapter lia = new SimpleAdapter(this,
arrlist,
R.layout.usercol,
new String[] { "corpid", "corpname" },
new int[] { R.id.cpid, R.id.cpname });
listv.setAdapter(lia);

热点排行