asked    Alston     2018-10-22       android       71 view        3 Answers

[SOLVED] How to access view inside activity from adapter in android?

Does anyone knows how to access adapter imageView inside activity to hide the view. Please specify any example.

  3 Answers  

        answered    Dean     2018-10-22      

I hope this will work for you.

By using SharedPreferences we can easily hide the view from activity or fragment.

Save flag in SharedPreferences i.e true from activity.

If you are using Recyclerview then in onBindViewHolder method check condition


        answered    Dorothy     2018-10-22      

Go to onBindViewHolder of the adapter and take the id of your imageview and code like this holder.mImgVw.setVisibility(View.GONE);

        answered    Monica     2018-10-22      

You should not directly interact with the ImageView, instead you can use notifyItemChanged() to update the ImageView state in the Adapter. But, you need to slightly modify your Adapter code by adding a flag in your model data or using SparseBooleanArray as a mechanism to saving the ImageView state.

Here the example:

public class Adapter ... {
  private SparseBooleanArray mSelectedItems;
  private List<YourModel> mItems;

  public Adapter(List<YourModel> items) {

    mItems = items;
    mSelectedItems = new SparseBooleanArray();

  public void onBindViewHolder(....) {
    int itemPosition = viewHolder.getAdapterPosition();
    YourModel item = items.get(itemPosition);

    boolean visible = mSelectedItems.get(itemPosition);   
    viewHolder.imageView.setVisibility(visible? View.VISIBLE: View.GONE);


  public void setItemVisibilityByPosition(int position, boolean visible) {
    mSelectedItems.put(position, visible);


You can change the image visibility with:

 // Assume the mAdapter is your Adapter
 mAdapter.setItemVisibilityByPosition(5, true);

Your Answer

 2018-10-22         Alfred

Laravel / MySQL when using AVG (only count first row return on a given id) - how?

My AVG(rank) will return 2 and 34 clicksSum in this case. But how can I get it to only count the first row of ranks? So that it will only take one rank of each keyword_id from each date in the interval.$interval = \DB::table('keywords')->selectRaw('keyword, url, AVG(rank) rankAvg, SUM(clicks) clicksSum ')->join('ranks', '', '=', 'ranks.keyword_id')->whereBetween('', array('2018-07-20','2018-07-29'))->orderBy('clicksSum', 'DESC')->groupBy('')->paginate(50);Table: Keywordsid keyword1 testTable: Ranksid keyword_id rank url ...
 mysql                     1 answers                     50 view
 2018-10-22         Brady

Laravel: Expression #3 of SELECT list is not in GROUP BY (Querying a Many-to-Many relationship)

I got a project with the Models Menu and User, which are in a Many-to-Many relationship.On one site I show the past menus per calender week, on the other I want to show the order history of a specific user per calender week.I got the menu history working with the following query:public static function archives() { return Menu::selectRaw('week(date, 1) as kw, year(date) as year') ->orderByRaw('min(date) asc') ->groupBy('kw', 'year') ->get(); }Now i thought about the same query for the User, but I get errors ...
 laravel                     1 answers                     52 view
 2018-10-22         Berg

Eloquent - How to use "Has Many Through" relation?

I have three tables - products, features and product_feature - asproducts - id - namefeatures - id - keyproduct_feature - product_id - feature_id - valueI was retrieve all (key, value) pairs for a product. The SQL statement isSELECT key, value FROM productsJOIN product_feature pfON pf.product_id = "Product ID"JOIN features fON = pf.feature_idHow do I established that relationship// Inside Product modelfunction features() { // Has many through relationship} This is a BelongsToMany relationship:public function features() { return $this->b...
 eloquent                     1 answers                     49 view