未在自定义适配器列表视图上设置值

Values are not set on the custom adapter list view

我有一个带有自定义适配器的列表视图。我正在尝试使用适配器为列表视图设置值。但是这些值没有在 运行 时设置,但是在使用简单适配器实现时它可以工作。我的自定义Adapter代码如下

   public class dataListAdapter extends SimpleAdapter {
    // HashMap<String, String> map = new HashMap<String, String>();
    List<HashMap<String, String>> data = new ArrayList();

    public dataListAdapter(Context context,
            List<HashMap<String, String>> data, int resource,
            String[] from, int[] to) {

        super(context, data, resource, from, to);
        this.data = data;

    }

    @Override
    public Object getItem(int arg0) {
        if (null != data) {
            try {
                return data.get(arg0);
            } catch (IndexOutOfBoundsException e) {
                return null;
            }
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView,
            final ViewGroup parent) {
        View row = convertView;
        if (row == null) {
            LayoutInflater mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = mInflater
                    .inflate(R.layout.listview_layout, parent, false);
        }

        Button vd = (Button) row.findViewById(R.id.viewDetails);
        // Button gd = (Button) row.findViewById(R.id.getDirections);
        Button ra = (Button) row.findViewById(R.id.reqAppointment);
        final OnClickListener vdClickListener = new OnClickListener() {
            @Override
            public void onClick(View v) {
                ListView listView = (ListView) parent;
                dataListAdapter adapter = (dataListAdapter) listView
                        .getAdapter();

                HashMap<String, String> item = (HashMap<String, String>) adapter
                        .getItem(position);

                // listView.getAdapter().get
                Toast.makeText(getApplicationContext(),
                        "vd clicked  Id  " + item,
                        Toast.LENGTH_LONG).show();
            }
        };

        final OnClickListener gdClickListener = new OnClickListener() {
            @Override
            public void onClick(View v) {

                Toast.makeText(getApplicationContext(),
                        "gdclicked  Id  ", Toast.LENGTH_LONG)
                        .show();
            }
        };

        final OnClickListener ravClickListener = new OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getApplicationContext(),
                        "req appclicked  Id  ",     Toast.LENGTH_LONG)
                        .show();
            }
        };

        vd.setOnClickListener(vdClickListener);
        // gd.setOnClickListener(gdClickListener);
        ra.setOnClickListener(ravClickListener);
        return row;
    }
}

这就是我将值设置为自定义值的方式adapter.But列表视图中未设置值。

        String[] from = { "flag", "txt", "cur", "vd", "gd",
            "ra" };

    // Ids of views in listview_layout
    int[] to = { R.id.flag, R.id.name, R.id.spec,
            R.id.vd, R.id.gd, R.id.ra};

    // Instantiating an adapter to store each items
    // R.layout.listview_layout defines the layout of each item

    adapter = new dataListAdapter(getBaseContext(), aList,
            R.layout.listview_layout, from, to);

    // new CallToServer(adapter, aList).execute("");
    // Getting a reference to listview of main.xml layout file
    HashMap<String, String> hm = new HashMap<String, String>();
    hm.put("txt", "Name  : " + "name");
    hm.put("cur", "spec: " + "spec");
    hm.put("flag", Integer.toString(0x7f020001));
    hm.put("but1", "");
    hm.put("but2", "");
    hm.put("but3", "");
    hm.put("ID", "100");
    aList.add(hm);
    System.out.println("Adapter object    " + adapter);
    adapter.notifyDataSetChanged();
    ListView listView = (ListView) findViewById(R.id.listview);
    // Setting the adapter to the listView
    listView.setAdapter(adapter);
    listView.setOnScrollListener(this);
    // setContentView(listView);

谁能指导我哪里出错了,因为设置到自定义适配器的值没有显示在列表视图中。

我已经尝试将 onClickListener 添加到按钮并打印该项目,并显示该项目的值,例如显示在 HashMap 中添加的名称、Id 等,因此它在渲染中存在问题只要 ?当我对 xml 中的值进行硬编码时,也会显示这些值。谁能解释一下可能是什么问题。

我认为需要的更改是在 getView() 方法中,我在其中添加了以下代码,它起作用了。这与我在 onClickListener()

中使用的代码相同
TextView textView=(TextView)row.findViewById(R.id.specialization);
HashMap<String, String> item = (HashMap<String, String>) adapter.getItem(position);


 textView.setText(item.get("txt"));

我将对图像等其他领域做同样的事情。如果这个想法是错误的,请投反对票和评论。我想我什至还可以使用取景器。