表格布局中带有列表视图的微调器的奇怪行为

时间:2012-01-19 11:22:44

标签: android listview spinner tablelayout

我正在尝试将表格布局放在列表视图中的表格布局中我有一个旋转器没有正确显示它在宽度上拉伸并且看起来不太好。我在CustomAdapter的getView()方法中扩展了表格布局,扩展了BaseAdapter

@Override
        public View getView(int position, View convertView, ViewGroup parent) {
            final int pos = position;
            final ViewHolder fHolder;
            ViewHolder holder ;
            View view = null;

            if(convertView == null) { // InflateViewHelper class is returning
                                     // object of View class In InflateViewHelper class
                                    //i have written
                                //View v = inflater.inflate(R.layout.table_layout, null); 

                InflateViewHelper inflateView = new InflateViewHelper(inflater, aShoppingItem.get(position), mContext);
                view = inflateView.createView();


                holder = new ViewHolder();
                holder.txtUnitPrice = (TextView) view.findViewById(R.id.txtUnitPrice);
                holder.txtTotalPrice = (TextView) view.findViewById(R.id.txtTotalPrice);
                holder.spinner = (Spinner) view.findViewById(R.id.spinner);

                view.setTag(holder);

            }
            else {

                view = convertView;
                holder = (ViewHolder)convertView.getTag();

            }
fHolder = holder;
            holder.spinner.setOnItemSelectedListener(
                    new OnItemSelectedListener() {

                        @Override
                        public void onItemSelected(AdapterView<?> parent, View view, int iposition, long id)
                        {

                            value = parent.getItemAtPosition(iposition).toString();

                            if( pos<totalItems.size())
                                totalItems.set(pos, value);
                            else
                                totalItems.add(pos,value);



                            int number = Integer.parseInt(value);
                            int unit = Integer.parseInt(fHolder.txtUnitPrice.getText().toString());
                            String total =  String.format("%d", unit*number);
                            fHolder.txtTotalPrice.setText(total);
                            String amnt = fHolder.txtTotalPrice.getText().toString();
                            Log.v("AMOUNT", amnt);

                            if( pos< totalAmount.size())
                                totalAmount.set(pos, amnt);
                            else
                                totalAmount.add(pos, amnt);

                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> parent) {
                            totalItems.add(pos, value);
                            Log.v("VALUE@@@@", value);          
                        }

            });

            int number = Integer.parseInt(value);
            int unit =         Integer.parseInt(holder.txtUnitPrice.getText().toString());
            String total =  String.format("%d", unit*number);
            holder.txtTotalPrice.setText(total);

            return view;
        }

如果我在简单的表格布局中尝试此代码,它可以正常工作 可以告诉我哪里出错了

1 个答案:

答案 0 :(得分:1)

经过很长一段时间才得到解决这个问题的方法。 为了解决这个问题,我使用了一个9补丁图像,并把它作为旋转器的背景,我得到更苗条的旋转器。我从this link

得到了这个答案