簡體   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