新手求教!!!
public List<User> findAllUser(){List<User> users = new ArrayList<User>();
Cursor userCursor=super.sd.query("user", new String[]
{"_id","title", "name", "tel", "email","address"}, null, null, null, null, null);
int count = userCursor.getCount();
if (count == 0 ||
!userCursor.moveToFirst()) {
//当前没有记录
return null;
}
for(int i=0;i<count;i++){
User u=new User();
u.setID(userCursor.getInt(0));
u.setTitle(userCursor.getString(1));
u.setName(userCursor.getString(2));
u.setTel(userCursor.getInt(3));
u.setEmail(userCursor.getString(4));
u.setAddress(userCursor.getString(5));
users.add(u);
userCursor.moveToNext();
}
/*这是我写得userDao*/
我要在另一个Activity 里取出查询的全部数据用listView显示出来
public class QueryActivity extends Activity {
UserDao userdao=null;
private ListView m_listview;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.query);
userdao=new UserDao(this);
userdao.openDatabase();
List<User> users = userdao.findAllUser();
m_listview = new ListView(this);
m_listview.setAdapter(new ArrayAdapter<String>(this, , users));
setContentView(m_listview);
}
}
这下面 怎么写~~~~~~~~~~~~~~~~~~~~ --------------------编程问答-------------------- ArrayList<Map<String, Object>> userList = new ArrayList<Map<String, Object>>();
for (int i = 0; i < m_listview.size(); i++) {
Map<String, Object> item = new HashMap<String, Object>();
item.put("username", users.get(i).toString);
item.put("id",String.valueOf(mTableID[i]));
userList .add(item);
}
--------------------编程问答-------------------- 那个Adapter还得传一些参数 --------------------编程问答-------------------- 不对吧、、、、、 --------------------编程问答-------------------- 你是什么问题啊,说清楚一点 --------------------编程问答-------------------- 是在queryActivity 里显示所有查出得数据以ListView来显示 我上面的全部查找语句写好了 下面的queryActivity 里 写得有问题 应该怎么写 怎么写简单点 --------------------编程问答-------------------- 搞定了
List<User> users = userdao.findAllUser();
ArrayList<Map<String, Object>> userList = new ArrayList<Map<String, Object>>();
for (int i = 0; i < users.size(); i++) {
Map<String, Object> item = new HashMap<String, Object>();
item.put("user", users.get(i).toString());
userList .add(item);
}
lv = new ListView(this);
lv.setAdapter(new ArrayAdapter(this, android.R.layout.易做图_list_item_1, userList));
setContentView(lv);
}
我在实体类里重写了toString 方法就取出来了 --------------------编程问答-------------------- 恭喜楼主,大家都是新手啊,这个我正好前几天接触了点,以后可以互相学习,给点分呗,谢了 --------------------编程问答-------------------- 大哥怎么不结贴啊,就给点分呗,大家都不容易啊
补充:移动开发 , Android