Note that there are some explanatory texts on larger screens.

plurals
  1. POListView - getView is called too much times
    primarykey
    data
    text
    <p>I know there are few questions regarding this issue of 'getView called few times' but my problem is little different.</p> <p>I have a custom listView with custom row ( used a row_layout.xml). It generally works well. At the beginning I had a problem with multiple calls to getView and it was fixed by using one of the methods I saw here in stackoverflow. ( using the 'usedPositions' array).</p> <p>now, I see in the logs this scenario: getView pos 0, getView pos 1, getView pos 0 , getView pos 1. This caused my rows to be doubled. It happens only when I call a new activity that covers the current activity and then close that activity. ( for example, open the camera activity and then close it).</p> <p>I will show my code:</p> <pre><code>public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub View row = convertView; Toast toast = Toast.makeText(this.context, "getView " + position, 1000); toast.show(); String pos = Integer.toString(position); if (!usedPositions.contains(pos)) { CardHolder holder = null; if(row == null) { LayoutInflater inflater = ((Activity)context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, parent, false); holder = new CardHolder(); //holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon); holder.txtCouponTitle = (TextView)row.findViewById(R.id.txtTitle); holder.txtBusinessName = (TextView)row.findViewById(R.id.txtBusinessName); row.setTag(holder); } else { holder = (CardHolder)row.getTag(); } Card card = data.get(position); holder.txtCouponTitle.setText(card.couponTitle); holder.txtBusinessName.setText(card.businessName); //holder.imgIcon.setImageResource(card.icon); TableLayout table = (TableLayout)row.findViewById(R.id.imagesTable); for (int r=1; r&lt;=1; r++){ TableRow tr = new TableRow(this.context); for (int c=1; c&lt;=10; c++){ ImageView im = new ImageView (this.context); im.setImageDrawable(this.context.getResources().getDrawable(c&lt;= card.numberOfStamps ? R.drawable.stamp_red :R.drawable.stamp_grey)); im.setPadding(6, 0, 0, 0); //padding in each image if needed //add here on click event etc for each image... //... tr.addView(im, 40,40); } table.addView(tr); } // Your code to fill the imageView object content usedPositions.add(pos); // holds the used position } else usedPositions.remove(pos); return row; } </code></pre> <p>Can you tell me what's wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload