3

在 getView 里面 addprod.setOnClickListener 我正在使两个视图可见,如果我初始化,你会在图像中看到 0 和减号按钮

final Button decprod=(Button)convertView.findViewById(R.id.decprod);
final TextView disprod=(TextView)convertView.findViewById(R.id.disprod);

像这样,即两个视图都是最终视图,那么我将两个视图都显示在我想要的位置,但是如果我按下 addprod 按钮删除最终视图,那么两个视图在其他地方都是可见的,正如您在这张图片中看到的那样,最终的.. ...我知道匿名内部类只能访问最终的封闭方法的变量,或者我们可以将其声明为全局变量,但如果我全局声明,我无法使正确的视图可见

在此处输入图像描述

 public class ItemListBaseAdapter extends BaseAdapter {


            private  ArrayList<HashMap<String, String>> itemDetailsrrayList;
             Bitmap bitmap[];
                Context context1;
                String ab;




            private LayoutInflater l_Inflater;

            public ItemListBaseAdapter(Context context, ArrayList<HashMap<String, String>> mylist)
            {

                itemDetailsrrayList = mylist;
                //l_Inflater = LayoutInflater.from(context);
                context1=context;

            }

            public int getCount() {
                return itemDetailsrrayList.size();

            }

            public Object getItem(int position) {
                return itemDetailsrrayList.get(position);
            }

            public long getItemId(int position) {

                return position;
            }




            public View getView( final int position, View convertView, ViewGroup parent)
            {
              int ruban=3;

                //final ViewHolder holder;


                if (convertView == null) {
                    l_Inflater = LayoutInflater.from(context1);

                     convertView = l_Inflater.inflate(R.layout.list1, null,true);




                }


                TextView txt_itemName = (TextView) convertView.findViewById(R.id.textView1);
                TextView txt_itemDescription = (TextView) convertView.findViewById(R.id.mrp1);
                TextView txt_itemPrice = (TextView) convertView.findViewById(R.id.ourprice1);
                TextView txt_itemSave = (TextView) convertView.findViewById(R.id.save1);
                //holder.txt_itemw = (TextView) convertView.findViewById(R.id.textView4);
                WebView itemimmm=(WebView)convertView.findViewById(R.id.imageView1);
                TextView t1 = (TextView) convertView.findViewById(R.id.t1);
                TextView t2 = (TextView) convertView.findViewById(R.id.t2);
                TextView t3 = (TextView) convertView.findViewById(R.id.t3);
                Button addprod=(Button)convertView.findViewById(R.id.addprod);
                final Button decprod=(Button)convertView.findViewById(R.id.decprod);
                final TextView disprod=(TextView)convertView.findViewById(R.id.disprod);
                decprod.setVisibility(View.GONE);
                disprod.setVisibility(View.GONE);

                txt_itemDescription.setPaintFlags(txt_itemDescription.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
                itemimmm.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);

                txt_itemName.setTypeface(AllItems.face);
                txt_itemDescription.setTypeface(AllItems.face);
                txt_itemPrice.setTypeface(AllItems.face);
                txt_itemSave.setTypeface(AllItems.face);
                //holder.txt_itemw.setTypeface(AllItems.face);
                t1.setTypeface(AllItems.rupee);
                t2.setTypeface(AllItems.rupee);
                t3.setTypeface(AllItems.rupee);
                //StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
                //StrictMode.setThreadPolicy(policy);
                txt_itemName.setText(itemDetailsrrayList.get(position).get("name"));
                txt_itemDescription.setText(itemDetailsrrayList.get(position).get("price"));
                txt_itemPrice.setText(itemDetailsrrayList.get(position).get("sp"));
                txt_itemSave.setText(itemDetailsrrayList.get(position).get("save"));
                //holder.txt_itemw.setText(itemDetailsrrayList.get(position).get("type"));
                itemimmm.loadUrl(itemDetailsrrayList.get(position).get("image"));
                if(itemDetailsrrayList.get(position).get("name").equals("Daughter")||itemDetailsrrayList.get(position).get("name").equals("Ethnic"))
                {
                Log.e("name", String.valueOf(itemDetailsrrayList.get(position).get("name")));
                //decprod.setVisibility(View.VISIBLE);
                //disprod.setVisibility(View.VISIBLE);
                }

                  // Log.e("before", "try");


            /*  try{

                        Log.e("try", String.valueOf(itemDetailsrrayList.get(position).get("image")));
                     Bitmap bitmap1 = BitmapFactory.decodeStream((InputStream) new URL(itemDetailsrrayList.get(position).get("image")).getContent());
                     itemimmm.setImageBitmap(bitmap1);
                    }catch(Exception ex){

                         ex.printStackTrace();
                         Log.e("error",String.valueOf(ex));
                     itemimmm.setImageResource(getResources().getIdentifier("ic_launcher", "drawable", getPackageName())); 

                        Log.e("catch", "catch");*/

                //prodImage.setImageResource(getResources().getIdentifier("sample", "drawable", getPackageName()));


                //itemimmm.setImageResource(getResources().getIdentifier("ic_launcher", "drawable", getPackageName())); 




                //holder.itemImage.setImageBitmap(bitmap[position]);

                /*if(){
                    disprod.setText(String.valueOf(Integer.parseInt(String.valueOf(disprod.getText()))));
                }*/


              addprod.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View arg0)
                    {


                        decprod.setVisibility(View.VISIBLE);
                        disprod.setVisibility(View.VISIBLE);





                    }
                });



                decprod.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View arg0)
                    {
                        //Log.v("item name", String.valueOf(itemDetailsrrayList.get(position).get("price")));

                    }
                });



               /* textView.setText(getelement()[position]);

                 ImageView imageView = (ImageView) convertView
                .findViewById(R.id.icon);
                 imageView.setImageBitmap(bitmap);*/




                    return convertView;




                   }




        }
4

3 回答 3

1

我认为您应该尝试在您的 ListActivity 中制作您的按钮操作,而不是在您的适配器中

于 2012-12-21T11:39:30.920 回答
1

很简单,尝试将项目位置添加到视图标签中,稍后在 OnClick(View v) 中检索该位置。

于 2013-07-16T23:36:26.803 回答
1

如果你申请了,分配给组件的位置将被删除。尝试使用隐形。

于 2012-12-21T12:55:57.300 回答