Note that there are some explanatory texts on larger screens.

plurals
  1. POOnClickListener not working for first item in GridView inside ViewPager
    primarykey
    data
    text
    <p>Inside ViewPager, there is a gridview which has a grid of single choice answers with textviews and images. When i clicked on any answer, the textview should change its color to RED else WHITE. Its working fine for all the other answers except the <strong>first one</strong>. When i first clicked on first answer in gridview, it doesn't change the color, on second click it turns to RED, but then when i change the option, the RED color doesn't change to WHITE for first option. Look at the screen below,</p> <p>Sorry Screen submission is not allowed for me as i am a new user...</p> <p>Inside <code>GridFragment#OnActivityCreated()</code>:</p> <pre><code>gridview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long arg3) { currentPage = new TestTopics().getCuttentPage(); tv = ((ViewHolder) v.getTag()).lbl; if(selectedValues.containsKey(currentPage)) { selectedValues.get(currentPage).setTextColor(Color.WHITE); selectedValues.remove(currentPage); selectedValues.put(currentPage, tv); selectedValues.get(currentPage).setTextColor(Color.RED); } else { selectedValues.put(currentPage, tv); selectedValues.get(currentPage).setTextColor(Color.RED); } } }); </code></pre> <p><code>ImageAdapter#getView()</code> method:</p> <pre><code>public View getView(int position, View convertView, ViewGroup parent) { numTopics = mTopicList.getNumTopics (); ViewHolder holder; holder = new ViewHolder(); if (convertView == null) { int layoutId = R.layout.demo_pager_grid_item; LayoutInflater li = ((Activity) mContext).getLayoutInflater(); childView = li.inflate (layoutId, null); holder.img = (ImageView) childView.findViewById(R.id.image); holder.lbl = (TextView) childView.findViewById(R.id.title); childView.setTag(holder); } else { childView = convertView; holder = (ViewHolder) childView.getTag(); } if (childView != null) { // Set the width and height of the child view. childView.setLayoutParams(new GridView.LayoutParams(mCellWidth, mCellHeight)); int j = position + mImageOffset; if (j &lt; 0) j = 0; if (j &gt;= numTopics) j = numTopics - 1; imageView = (ImageView) childView.findViewById (R.id.image); if (imageView != null) { Resources res = mContext.getResources (); int imagePadding = res.getDimensionPixelSize (R.dimen.grid_image_padding); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setBackgroundResource (R.color.background_grid1_cell); imageView.setPadding (imagePadding, imagePadding, imagePadding, imagePadding); imageView.setImageBitmap (mTopicList.getTopicImage (j)); imageView.setTag (new Integer (j)); } textView = (TextView) childView.findViewById (R.id.title); if (textView != null) { textView.setText(mTopicList.getTopicTitle (j)); textView.setTag (mTopicList.getTopicTitle (j)); holder.lbl.setTag(mTopicList.getTopicTitle (j)); } } return childView; } </code></pre> <p>I have seen this link : <a href="https://stackoverflow.com/questions/11778228/onclicklistener-not-working-for-first-item-in-gridview">OnClickListener not working for first item in GridView</a>, and follow the answer, but didn't get succeed on it...</p> <p>Where I'm going wrong?</p>
    singulars
    1. This table or related slice is empty.
    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.
    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