1

i have a multi column listview to show stocks list a company. Code works when work on small data. (they fit the screen, scrolling don't need.) but stock count as many as can't fit the screen. Below problems occured.

1. When a list item's details expand and scroll, another items selected, too. (for example i expand 3.stock, it selects 15.stock and 27.stock and 39.stock etc.etc. )

http://i.stack.imgur.com/CLRSJ.jpg

2. Another problem is details layout. Normally it have two tabs, but it shows too many tabs.

http://i.stack.imgur.com/E2MyX.png

here is my adapter class:

    public class StockListAdapter extends BaseAdapter
{
    public ArrayList<HashMap<String, String>> list;
    Activity activity;
    public ArrayList<EditText> editTextListMiktar = new ArrayList<EditText>();
    public ArrayList<String> stockNoList = new ArrayList<String>();
    public ArrayList<LinearLayout> stockLayoutList = new ArrayList<LinearLayout>();
    private String stokNo;
    private Context context;
    private boolean isDetail;
    private String birim;
    private String processType;
    private String processNo;
    private Object kodTuru;
    private boolean clearAlsaDeta;
    public static String x;

    public StockListAdapter(Activity activity, ArrayList<HashMap<String, String>> list, Context context,String kodTuru, String processNo, String processType, boolean clearAlsaDeta) {
        super();
        this.activity = activity;
        this.list = list;
        this.context = context;
        this.kodTuru = kodTuru;
        this.processNo = processNo;
        this.processType = processType;
        this.clearAlsaDeta = clearAlsaDeta;
    }

    @Override
    public int getCount()
    {
        return list.size();
    }

    @Override
    public Object getItem(int position)
    {
        return list.get(position);
    }

    @Override
    public long getItemId(int position)
    {
        // TODO Auto-generated method stub
        return 0;
    }

    static class ViewHolder
    {
        ImageView stockDetail;
        TextView stockNo;
        TextView stockCode;
        TextView stockName;
        Spinner stockBirim;
        TextView stockKdv;
        EditText stockMiktar;
        LinearLayout linearLayoutStockBase;
        LinearLayout linearLayoutStockDetail;
        TabHost TabHostStockDetail;
        ListView listviewDetailFiyat;
        ListView listviewDetailStok;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        final ViewHolder holder;
        LayoutInflater inflater = activity.getLayoutInflater();

        if (convertView == null)
        {
            convertView = inflater.inflate(R.layout.stocklistitems, null);
            holder = new ViewHolder();
            holder.linearLayoutStockBase = (LinearLayout) convertView.findViewById(R.id.linearLayoutStockBase);
            stockLayoutList.add(holder.linearLayoutStockBase);
            holder.stockDetail = (ImageView) convertView.findViewById(R.id.imageViewStockDetail);
            holder.stockNo = (TextView) convertView.findViewById(R.id.textViewStockNo);
            holder.stockCode = (TextView) convertView.findViewById(R.id.textViewStockCode);
            holder.stockName = (TextView) convertView.findViewById(R.id.textViewStockName);
            holder.stockBirim = (Spinner) convertView.findViewById(R.id.spinnerStockBirim);
            holder.stockKdv = (TextView) convertView.findViewById(R.id.textViewStockKdv);
            holder.stockMiktar = (EditText) convertView.findViewById(R.id.editTextStockMiktar);
            editTextListMiktar.add(holder.stockMiktar);
            holder.linearLayoutStockDetail = (LinearLayout) convertView.findViewById(R.id.linearLayoutStockDetails);
            holder.TabHostStockDetail = (TabHost) convertView.findViewById(R.id.tabHostStokList);
            holder.listviewDetailFiyat = (ListView) convertView.findViewById(R.id.listViewStoklistDetailFiyat);
            holder.listviewDetailStok = (ListView) convertView.findViewById(R.id.listViewStoklistDetailStok);
            holder.stockMiktar.setText("");
            // setMiktar(stokNo, processNo, holder.stockMiktar,
            // holder.linearLayoutStockBase);
            convertView.setTag(holder);
        } else
        {
            holder = (ViewHolder) convertView.getTag();
        }

        final HashMap<String, String> map = list.get(position);
        holder.stockNo.setText(map.get("StokNo"));
        stokNo = map.get("StokNo");
        stockNoList.add(stokNo);
        holder.stockCode.setText(map.get("StokCode"));
        holder.stockName.setText(map.get("StokName"));
        holder.stockKdv.setText(map.get("StokKdv"));
        holder.stockBirim.setAdapter(TableUtils.SpinnerAdapter(context, "SELECT BIRIM FROM STOKBIRI WHERE STOK_NO=" + stokNo, null));
        Functions.selectPrefItemsToSpinner(holder.stockBirim, map.get("StokBirim"));
        Functions.setSpinnerEnable(holder.stockBirim);
        holder.stockMiktar.setText("");

        holder.stockMiktar.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_CLASS_PHONE);

        // tab detail kısmının eklenmesi
        tabDetailSetup(stokNo, holder.TabHostStockDetail, holder.listviewDetailFiyat, holder.listviewDetailStok);

        // detay göster
        holder.stockDetail.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                if (!isDetail)
                {
                    holder.linearLayoutStockDetail.setVisibility(View.VISIBLE);
                    holder.stockDetail.setBackgroundResource(R.drawable.box_delete_expand);
                    isDetail = true;
                } else
                {
                    holder.linearLayoutStockDetail.setVisibility(View.GONE);
                    holder.stockDetail.setBackgroundResource(R.drawable.box_plus);
                    isDetail = false;
                }
            }
        });

        holder.linearLayoutStockBase.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                if (!isDetail)
                {
                    holder.linearLayoutStockDetail.setVisibility(View.VISIBLE);
                    holder.stockDetail.setBackgroundResource(R.drawable.box_delete_expand);
                    isDetail = true;
                } else
                {
                    holder.linearLayoutStockDetail.setVisibility(View.GONE);
                    holder.stockDetail.setBackgroundResource(R.drawable.box_plus);
                    isDetail = false;
                }

            }
        });

        holder.stockMiktar.addTextChangedListener(new TextWatcher()
        {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count)
            {
                map.put("StokMiktar", s.toString());
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after)
            {
                // TODO Auto-generated method stub
            }

            @Override
            public void afterTextChanged(Editable s)
            {
                map.put("StokMiktar", s.toString());
            }
        });

        holder.stockBirim.setOnItemSelectedListener(new OnItemSelectedListener()
        {

            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long arg3)
            {
                birim = holder.stockBirim.getItemAtPosition(position).toString();
                map.put("StokBirim", birim);

            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0)
            {

            }
        });

        return convertView;
    }

        public void tabDetailSetup(String stokNo, TabHost th, ListView lsFiyat, ListView lsStok)
    {
        th.setup();
        TabSpec spec1 = th.newTabSpec("Tab 1");
        spec1.setContent(R.id.tabStoklistFiyat);
        spec1.setIndicator("Fiyatlar");
        TabSpec spec2 = th.newTabSpec("Tab 2");
        spec2.setIndicator("Stoklar");
        spec2.setContent(R.id.tabStoklistStok);
        th.addTab(spec1);
        th.addTab(spec2);
...      }
4

1 回答 1

0

第一个问题是您没有设置 linearLayoutStockDetail 的可见性。android 重用视图中的 ListView 用于行。当您打开第 3 行的详细视图并滚动底部时 - android 会重用您的第 3 行。您为文本字段设置新值,但不要隐藏详细视图。

第二个问题,我猜,同样的。您没有显示 tabDetailSetup 方法,但我认为您每次都添加选项卡。您需要先清除旧标签。

请记住,当您在适配器中使用 convertView 时,您会获得具有自己属性的旧视图,这是您上次设置的。

于 2013-08-12T12:34:06.243 回答