Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8374077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:50:29+00:00 2026-06-09T14:50:29+00:00

I’m doing a tweer feeder and I don’t know how to manage images using

  • 0

I’m doing a tweer feeder and I don’t know how to manage images using the viewHolder pattern

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    View v = convertView;
    if (v == null) {               
         inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);         
         v = inflater.inflate(R.layout.activity_result, null);
         holder = new ViewHolder();

         holder.name = (TextView) v.findViewById(R.id.name);
         holder.tweet = (TextView) v.findViewById(R.id.tweet);
         holder.avatar = (ImageView) v.findViewById(R.id.avatar);
         Log.v("TAG", "ACA SI LLEGE holder cargado");
         holder.name.setText(mitems.get(position).getFromUser());
         holder.tweet.setText(mitems.get(position).getText());


         task = new BackgroundAsyncTask(this, position);
         task.execute();


         v.setTag(holder);
    } else {              
     holder = (ViewHolder) convertView.getTag();          
     }                             
   return v; 

}



public class BackgroundAsyncTask extends AsyncTask<Void, Integer, Void>{

    private ResultsAdapter resultAdapter;
    private int position;
    private MyApplication myapp;
    private Bitmap bitmap;

    public BackgroundAsyncTask(ResultsAdapter adptr, int position){
        this.resultAdapter = adptr;
        this.position = position;
    }

    @Override
    protected Void doInBackground(Void... params) {

          try {
                for(int i = 0; i < mitems.size(); i++){               
                bitmap = BitmapFactory.decodeStream((InputStream)
                  new URL(mitems.get(i).getProfileImageUrl()).getContent()); 
          }
          } catch (MalformedURLException e) {   
              e.printStackTrace(); 
          } catch (IOException e) {   
              e.printStackTrace(); 
          } 

        return null;
    }

    @Override  
    protected void onProgressUpdate(Integer... values) {     
            myapp.setProgreso(values[0]);
    }
    @Override
    protected void onPostExecute(Void result){       
        holder.avatar.setImageBitmap(bitmap);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:50:30+00:00Added an answer on June 9, 2026 at 2:50 pm

    Solution:

    public class ResultsAdapter extends BaseAdapter{
    
    private Context mContext;
    private LayoutInflater inflater;
    private List<Result> mitems;
    private List<ImageView> allImageViews = new ArrayList<ImageView>();
    private ViewHolder holder;
    private BackgroundAsyncTask task;
    
    public ResultsAdapter(Context c, List<Result> mitems){
        mContext = c;
        inflater = LayoutInflater.from(mContext);
        this.mitems = mitems;
    } 
    
    @Override
    public int getCount() {
        return mitems.size();
    }
    
    @Override
    public Object getItem(int position) {
        return mitems.get(position);
    }
    
    @Override
    public long getItemId(int position) {
        return position;
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    
        View v = convertView;
        if (v == null) {               
             inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);         
             v = inflater.inflate(R.layout.activity_result, null);
             holder = new ViewHolder();          
             holder.name = (TextView) v.findViewById(R.id.name);
             holder.tweet = (TextView) v.findViewById(R.id.tweet);
             holder.avatar = (ImageView) v.findViewById(R.id.avatar);
             holder.name.setVisibility(holder.name.INVISIBLE);
             holder.tweet.setVisibility(holder.tweet.INVISIBLE);
             holder.name.setText(mitems.get(position).getFromUser());
             holder.tweet.setText(mitems.get(position).getText());
    
             allImageViews.add(holder.avatar);
    
             task = new BackgroundAsyncTask();
             task.execute();
             holder.name.setVisibility(holder.name.VISIBLE);
             holder.tweet.setVisibility(holder.tweet.VISIBLE);
    
             v.setTag(holder);
        } else {              
         holder = (ViewHolder) convertView.getTag();          
         }                             
       return v;    
    }
    public class BackgroundAsyncTask extends AsyncTask<Void, Integer, Void>{
    
        private MyApplication myapp;
        private List<Bitmap> bitmaps;
        private ProgressDialog dialog;
    
        public BackgroundAsyncTask(){
            bitmaps = new ArrayList<Bitmap>();
            dialog = new ProgressDialog(mContext);
            dialog.setTitle("Twitter Searching App");
            dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            dialog.setMessage("Searching...");
            dialog.setCancelable(true);
            dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel",   
                            new DialogInterface.OnClickListener() {   
                              public void onClick(DialogInterface dialog, int which) {   
                                dialog.cancel();    
                              }   
                            }   
                          );
        }
    
        @Override
        protected Void doInBackground(Void... params) {
             for(int i =0; i < allImageViews.size(); i++){                             
                  try {               
                        bitmaps.add(BitmapFactory.decodeStream((InputStream)
                          new URL(mitems.get(i).getProfileImageUrl()).getContent())); 
                  } catch (MalformedURLException e) {   
                      e.printStackTrace(); 
                  } catch (IOException e) {   
                      e.printStackTrace(); 
                  }                      
             }
    
            return null;
        }
        @Override
        protected void onPreExecute() {                 
            dialog.show();     
        }
    
        @Override  
        protected void onProgressUpdate(Integer... values) {     
                myapp.setAdptr(ResultsAdapter.this);
        }
        @Override
        protected void onPostExecute(Void result){       
            for(int i =0; i < allImageViews.size(); i++){ 
                allImageViews.get(i).setImageBitmap(bitmaps.get(i));
                holder.avatar = allImageViews.get(i);
            }
            if (dialog.isShowing()) {             
                dialog.dismiss();         
                }
        }
    
     }
    
    static class ViewHolder{
        TextView name, tweet;
        ImageView avatar;
    }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am doing a simple coin flipping experiment for class that involves flipping a
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.