Strange behavior of listview in android

    @Override
public View getView(final int position, View convertView, ViewGroup parent) {
    View view = convertView;
    if (view == null) {
        LayoutInflater mInflater = (LayoutInflater) mContxt
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = mInflater.inflate(R.layout.row_link_product_distributor,
                null);
    }
    holder = new ViewHolder();
    holder.linktoprodisarraylist = listProduct.get(position);

    holder.imgProduct = (ImageView) view.findViewById(R.id.productimg);
    holder.txtProductName = (TextView) view
            .findViewById(R.id.txtproductname);
    holder.txtDistributorNametxt = (TextView) view
            .findViewById(R.id.txtdistributornametxt);
    holder.brand_name = (TextView) view.findViewById(R.id.barnd_nametxt);
    holder.manf_name = (TextView) view.findViewById(R.id.manf_nametxt);

    holder.txtDistributorNametxt.setTag(position);
    view.setTag(holder);
    holder.imgProduct.setImageResource(holder.linktoprodisarraylist
            .getProductImgID());
    holder.txtProductName.setText(holder.linktoprodisarraylist
            .getProductName());
    holder.txtDistributorNametxt.setText(holder.linktoprodisarraylist
            .getFavDistName());
    holder.brand_name.setText(holder.linktoprodisarraylist.getBrandName());
    holder.manf_name.setText(holder.linktoprodisarraylist.getManName());
    holder.txtDistributorNametxt.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(final View v) {
            final String productId = arraylist.get(position).getProductID();
            TextView disname = (TextView) v;
            String Disname_value = disname.getText().toString();
            if (Disname_value.equalsIgnoreCase("Select Distributer")) {
                alreadyassigndisid = "0";
            } else {
                alreadyassigndisid = getDistributorid(Disname_value);
            }

            final Dialog dialog = new Dialog(mContxt);
            dialog.setContentView(R.layout.row_distributor_name);
            dialog.setTitle("Select Distributer");
            dailogListView = (ListView) dialog.findViewById(R.id.disnamelv);
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                    mContxt, android.R.layout.simple_list_item_1,
                    listDistributorname);
            dailogListView.setAdapter(adapter);
            dailogListView
                    .setOnItemClickListener(new OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> parent,
                                View view, int position, long id) {
                            TextView disname = (TextView) v;
                            disname.setText(listDistributorname
                                    .get((Integer) position));
                            int dsiId = Distributor_idlist.get(position)
                                    .getDisID();
                            insertFavProduct_DisIntoDb(userId,
                                    Integer.valueOf(alreadyassigndisid),
                                    dsiId, String.valueOf(productId),
                                    position);
                            dialog.dismiss();
                        }
                    });
            dialog.show();
        }
    });
    return view;
} 

i am using listview,there textview on click of textview i open a dilog and set this value to textview but when ever i scroll the changes get revert,selected distributor name not show. Did anybody tell me what is wrong in this code.


Source: android

Leave a Reply