0

I have a SQLite. I'm listing search history in MainActivity. When user searching username, I'm saving username and picture url in SQLite.

But I have to use picasso for set image to ImageView in GridView with SQLite results. I couldn't find a resolve.

SQLite codes:

    @Override
public void onResume(){
    super.onResume();
    Database db = new Database(getApplicationContext());
    HistoryList = db.History_list();
    if(HistoryList.size()==0){
        image_button = (ImageButton) findViewById(R.id.users_history_timer);
        image_button.setVisibility(View.VISIBLE);

        text_view = (TextView) findViewById(R.id.users_history_timer_text);
        text_view.setVisibility(View.VISIBLE);
    }else{
        image_button = (ImageButton) findViewById(R.id.users_history_timer);
        image_button.setVisibility(View.INVISIBLE);

        text_view = (TextView) findViewById(R.id.users_history_timer_text);
        text_view.setVisibility(View.INVISIBLE);

        db_usernames = new String[HistoryList.size()];
        db_pictures = new String[HistoryList.size()];
        history_ids = new int[HistoryList.size()];
        for(int i=0;i<HistoryList.size();i++){
            db_usernames[i] = HistoryList.get(i).get("username");
            db_pictures[i] = HistoryList.get(i).get("picture");
            history_ids[i] = Integer.parseInt(HistoryList.get(i).get("id"));
        }
        Gridm = (GridView) findViewById(R.id.grid_view);
        Adapterm = new ArrayAdapter<String>(this, R.layout.search_history_list, R.id.usernames, db_usernames);
        Gridm.setAdapter(Adapterm);

        Gridm.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                    long arg3) {
                Intent intent = new Intent(getApplicationContext(), MainActivity.class);
                intent.putExtra("getUrl", db_usernames[arg2]);
                startActivity(intent);

            }
        });
    }
}

Anybody have a idea about it?

  • you can create custom adapter for your gridlayout and in adapter you can handle code to inflate view and bind it there using picasso. – karan Mar 30 '18 at 20:04

1 Answers1

0

I'd advise you to use RecyclerView with GridLayoutManager, example.

And inside onBindViewHolder method Picasso for show image in grid.

Yuri Misyac
  • 4,364
  • 2
  • 16
  • 32