繁体   English   中英

Listview打印对象不是字符串Java

[英]Listview prints Object not string java

我试图显示带有openERP / odoo之外的数据的listview。 OpenERP将我要使用的对象列表返回到列表视图中,但是它打印出“ Ljava.lang.object@number”。

listOfValues返回对象列表,在我的onPostExecute中,我想将其与listview连接。 但这是行不通的,有人建议吗?

私有类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);

我的模型是您创建的用于描述数据的类,

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM