使用Custom ArrayAdapter在ListView中显示

时间:2014-03-26 17:35:52

标签: android android-listview

我正在使用CustomArrayAdapter来显示ListItem和setTag。我只是将数据设置为列表项textview,但id也显示在每个数据旁边的单独textview中

如何避免显示该ID?

enter image description here

public class CustomArrayAdapter extends ArrayAdapter<String> {

        Context mContext;
        int layoutResourceId;
        String data[] = null;
        String id[] = null;

        public CustomArrayAdapter(Context mContext, int layoutResourceId, String[] data, String[] id) {

            super(mContext, layoutResourceId, data);

            this.layoutResourceId = layoutResourceId;
            this.mContext = mContext;
            this.data = data;
            this.id=id;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            if(convertView==null){
                // inflate the layout
                LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
                convertView = inflater.inflate(layoutResourceId, parent, false);
            }


            String objectItem = data[position];


            TextView textViewItem = (TextView) convertView.findViewById(R.id.book_item);
            textViewItem.setText(objectItem);
            textViewItem.setTag(id[position]);

            return convertView;

        }

    }

1 个答案:

答案 0 :(得分:0)

您的数据变量包含我认为的那些ID。您的数据字符串数组包含软件测试,0001等,...等等,检查您传入的数据