Change Gridview Element Visibility

I have a Gridview and a Custom adapter.

in my adapter, I have a static instance of ViewHolder.

static class ViewHolder { TextView _model,tPrice,pPrice; ImageView picture; } 

This is my ViewHolder. When the user clicked the button in the snippet, I just want to make TPrice GONE visible. When I create an adapter attribute, I send an integer parameter to tPrice VISIBLITY. But his data is still stored on static data. I want to change this area. I need an instance of my current view. I will throw it in my ViewHolder. After that I set the visibility. But how can I do this?

Here is getView and my constructor

 private int TFV = View.GONE; private int PFV= View.GONE; public ProductGridViewAdapter(Context p_context, int p_resourceId,ArrayList<Product> p_ProductList,int TFVisib,int PFVisib){ super(p_context,p_resourceId,p_ProductList); originalItems = p_ProductList; TFV = TFVisib; PFV = PFVisib; _ctx = p_context; //.... } public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = null; View row = convertView; if(row==null){ holder = new ViewHolder(); row = li.inflate(_resourceId, null); holder._model = (TextView) row.findViewById(R.id.o_model); holder.pPrice = (TextView) row.findViewById(R.id.product_pf); holder.tPrice = (TextView) row.findViewById(R.id.product_tf); holder.picture = (ImageView)row.findViewById(R.id.product_lv_image); row.setTag(holder); }else{ holder = (ViewHolder) row.getTag(); } Product f =null; if(originalItems!=null) f = originalItems.get(position); if (f != null) { holder._model.setText(f.GetCODE()); holder.pPrice.setText(f.GetPRICE()); holder.pPrice.setVisibility(PFV); holder.tPrice.setVisibility(TFV); holder.tPrice.setText(f.GetCURRENCY()); File imgFile = new File(uhandler.GetProductsFolderPath()+"/BIG"+f.GetCODE()+".jpg"); if(imgFile.exists()){ Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); holder.picture.setImageBitmap(myBitmap); } } return row; } 
+4
source share
2 answers

I solved my problem. I installed the adapter again. This method may be unsuccessful, but its work :)

0
source

In your custom adapter class, consider the getView() method, in which you can set the value to GONE or VISIBLE or INVISIBLE in tPrice TextView or any views if you want.

0
source

All Articles