Strange behavior of listview in Android
I am using a listview in which there is a textview.
A dialog is opened when the textView is clicked and the user can set a new value to the textview, but when ever I scroll the changes get reverted, and the selected distributor name is not displayed.
Can anybody tell me what is wrong in this code?
@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 adapter = new ArrayAdapter(
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;
}