【发布时间】:2019-02-10 09:03:40
【问题描述】:
我想知道这是在android studio中使用/ oop & sqlite在自定义列表视图中显示数据的方式吗?
在这个java页面中,我把它们分配在这里
public static Model txn;
public static SQLiteHelper mSQLiteHelper;
ListView mListView;
ArrayList<Model> mList;
RecordListAdapter mAdapter = null;
之后,我初始化了它们
mListView =findViewById(R.id.listView);
mList = new ArrayList<>();
mAdapter = new RecordListAdapter(this, R.layout.row, mList);
mListView.setAdapter(mAdapter);
这是我试图将它们全部抓取并展示出来的代码。我在mList.add(new Model(id, name, address, phone));这一行遇到了一个问题。
try{
SQLiteDatabase db = mSQLiteHelper.getReadableDatabase();
Cursor cursor = db.query("Table1", new String[]{"id", "name", "address", "phone"}, null,
null, null, null, null);
mList.clear();
while(cursor.moveToNext()){
int id = cursor.getInt(3);
String name = cursor.getString(0);
String address = cursor.getString(1);
String phone = cursor.getString(2);
mList.add(new Model(id, name, address, phone));
}
mAdapter.notifyDataSetChanged();
if (mList.size() == 0) {
Toast.makeText(this, "No record found...", Toast.LENGTH_SHORT).show();
}
mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int i, long l) {
return false;
}
});
}catch (Exception e){
e.printStackTrace();
}
这里是红色错误提示
Model() in Model cannot be applied to:
Expected Actual
Parameters: Arguments
id(int)
name(java.lang.String)
address(java.lang.String)
phone(java.lang.String)
这是我的模型页面
public class Model {
private int id;
private String name;
private String address;
private String phone;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}
我能做些什么来解决这个问题?提前谢谢...
【问题讨论】:
-
你好莱昂。可以分享一下你的 Model 课吗?
-
嗨。我已经编辑了我的模型。请检查一下。谢谢@JuanjoBerenguer
标签: android database sqlite oop