Listview 打印 Object not string java

Listview prints Object not string java

我正在尝试显示一个列表视图,其中包含来自 openERP/odoo 的数据。 OpenERP return 是我试图在列表视图中使用的对象列表,但它打印出 "Ljava.lang.object@number"。

listOfValues return 对象列表,在我的 onPostExecute 中我想将它与列表视图连接起来。但它不起作用,有人建议吗?

私有 class ListViewLoaderTask 扩展 AsyncTask{

    @Override
    protected SimpleAdapter doInBackground(String... strJson) {
        connector=new OpenerpRpc(getBaseContext());
        connector.Config();
        current_page += 1;
        listOffValues = getListOffFieldValues(current_page, false, listOffValues);

        String[] from = { "project_id"};
        int[] to = { R.id.tv_address};
        SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), listOffValues, R.layout.lv_gps_layout, from, to);
        return adapter;
    }
    /** Invoked by the Android on "doInBackground" is executed */
    @Override
    protected void onPostExecute(final SimpleAdapter adapter) {
        // Setting adapter for the listview
        mListView.setAdapter(adapter);

        for(int i=0;i<adapter.getCount();i++){

            HashMap<String, Object[]> hm = (HashMap<String, Object[]>) adapter.getItem(i);
            final HashMap<String, String> companyDetails = new HashMap<String, String>();
            Object po_ids = (Object[]) hm.get("project_id");
            Object[] ret=(Object[]) hm.get("project_id");
            Integer number =  ((Integer) hm.get("project_id")[0]);
            String projectId =  ((String) hm.get("project_id")[1]);
            companyDetails.put("project_id",projectId);

            adapter.notifyDataSetChanged();

            mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
                    String listName;
                    HashMap<String, String> hmDownload = new HashMap<String, String>();
                    String l = companyDetails.get("project_id");
                    Intent myIntent = new Intent(MainActivity.this, YardActivity.class);
                    myIntent.putExtra("id", Long.toString(id));
                    myIntent.putExtra("position", Integer.toString(position)); //Optional parameters
                    MainActivity.this.startActivity(myIntent);
                }
            });

        }
        progress.dismiss();
        Log.d("/****","Data from odoo is finished");
    }
}

这是我调试时的输出:

http://i62.tinypic.com/24esx87.png

我更新了示例,您可以看到我可以从列表中获取项目名称。但是,当我尝试可视化它时,它会打印出 java.lang 字符串。您的解决方案是唯一的解决方案吗?当我在我的列表视图中点击一个项目时,我得到了我点击的 projectId,那么为什么它不可视化字符串值呢?

HashMap<String, Object[]> hm = (HashMap<String, Object[]>)adapter.getItem(i);

改为

HashMap<String, MyModel[]> hm = (HashMap<String, MyModel[]>) adapter.getItem(i);

我的模型是 class 您创建的描述数据的模型,

看看ObjectItem.java http://www.javacodegeeks.com/2013/09/android-listview-with-adapter-example.html