【发布时间】:2016-09-03 02:55:47
【问题描述】:
对不起,我的英语不好。这是在列表视图中显示商店客户名称的数据库的一部分。我有以下代码:
private void updateCustomerList(){
mdatabase=new MiDataBase(mcontext);
customerList=new ArrayList<Customer>();
customerList=mdatabase.getallCustomer();//this call getallCustumer
customerListStr=new ArrayList<String>();
mlistView=getListView();
if(customerList==null||customerList.size()<=0){
customerListStr.add("NO SE HAN AÑADIDO CLIENTES");
unregisterForContextMenu(mlistView);
}else{
Customer item=new Customer();
for(int i=0;i<customerList.size();i++){
item=customerList.get(i);
customerListStr.add(item.getName());
}
registerForContextMenu(mlistView);
}
MyArrayAdapter marrayAdapter=new MyArrayAdapter(mcontext,customerListStr);
mlistView.setAdapter(marrayAdapter);
}
方法getallCustomer是:
public List<Customer>getallCustomer(){
ArrayList<String>marrayList=new ArrayList<String>();
List<Customer> mcustomerList=new ArrayList<Customer>();
marrayList.add(Customer.camposCust.name.toString());
Customer mcustumer=new Customer();
String[]marrayColumn=marrayList.toArray(new String[marrayList.size()]);
Cursor mcursor;
openDB();
mcursor=database.query(nombreT,marrayColumn,null,null,null,null,null);
mcursor.moveToFirst();
int mindex=mcursor.getColumnIndex(Customer.camposCust.name.toString());
while(mcursor.isAfterLast()==false){
mcustumer.setName(mcursor.getString(mindex));
mcustomerList.add(mcustumer);
mcursor.moveToNext();
}
mcursor.close();
closeDB();
return mcustomerList;
}
客户类是:
public class Customer
{
private String city;
private String address;
private String cel;
private String email;
private String name;
private int customerID;
public enum camposCust{
city,
address,
cel,
email,
name,
_customerID
}
public void setCity(String city)
{
this.city = city;
}
public String getCity()
{
return city;
}
public void setAddress(String address)
{
this.address = address;
}
public String getAddress()
{
return address;
}
public void setCel(String cel)
{
this.cel = cel;
}
public String getCel()
{
return cel;
}
public void setEmail(String email)
{
this.email = email;
}
public String getEmail()
{
return email;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setCustomerID(int customerID)
{
this.customerID = customerID;
}
public int getCustomerID()
{
return customerID;
}
}
问题是当我引入两个或多个项目时,在列表视图中只显示最后一个引入的项目不止一次,如下图:例如我介绍了三个项目:Juan、Peter 和 Joseph。胡安和彼得没有出现
我希望你能理解,有人可以帮忙。我将不胜感激,在此先感谢。
【问题讨论】:
标签: android database listview generics