@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;
}
我正在使用listview,因为有一个textview
单击textView并且用户可以为textview设置新值时会打开一个对话框,但是当我滚动更改时,将恢复,并且不会显示所选的分发服务器名称。
谁能告诉我这段代码有什么问题?
答案 0 :(得分:0)
如评论中所述,滚动时您的列表会被回收。当用户输入值时,您需要更新适配器中的列表。
答案 1 :(得分:0)
首先,您应该知道listview和适配器的工作原理。我推荐this post。 之前的评论/答案是正确的。您必须存储该值。