我有一个带有3个变量的简单自定义arraylist类,并且已将来自SQLite的数据存储到它们中,如下所示:

    List<String> nomess= produtoDAO.getAllProductsId(id);
    Cursor allrows = produtoDAO.getAllDataForSpinner(id);

    if (allrows.moveToFirst()) {
        do {

            String ID = allrows.getString(0);
            String NAME = allrows.getString(1);
            String PLACE = allrows.getString(2);
            SpinnerObject data = new SpinnerObject(ID, NAME, PLACE);
            nomes.add(data);

        } while (allrows.moveToNext());
    }


SpinnerObject类:

包装对象;

public class SpinnerObject {

private String id;
private String nome;
private String id_cliente;

public SpinnerObject(String _id, String _nome, String _id_cliente)
{
    _id = id;
    _nome = nome;
    _id_cliente = id_cliente;
}
}


我想知道如何获取存储的信息并立即转换为字符串数组列表。我尝试了nomes.get(position),但是它似乎不起作用(我得到了错误的object.SpinnerObject无法转换为java.util.List)。

请帮忙!提前致谢!

最佳答案

我收到错误对象.SpinnerObject无法转换为java.util.List


可能您正在尝试将SpinnerObject对象转换为List,因为nomes.get(position)应该返回SpinnerObject类对象而不是List

从清单中获取价值:

SpinnerObject objSpinner=nomes.get(position);


SpinnerObject类中创建getter方法:

public class SpinnerObject {
...

 public String getId(){
  return this.id;
 }

 public String getName(){
  return this.nome;
 }

}


现在使用objSpinner.getId()objSpinner.getName()访问所有值

10-04 18:14