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 7929181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:59:25+00:00 2026-06-03T19:59:25+00:00

I am building a android-based app to implement twitter search function. The button click

  • 0

I am building a android-based app to implement twitter search function. The button click only works for the first. If i change the search term and click the button again, it fails to refresh. Anyone can give me a hint?
`public class TwitterSActivity extends Activity implements OnClickListener{
EditText etQuery;
Button btnQuery;

class Tweet{
    public String username;
    public String message;
    public String image_url;
}

ArrayList<Tweet> tweets = new ArrayList<Tweet>();

@Override
public void onCreate(Bundle savedInstanceState) {
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    etQuery = (EditText) findViewById (R.id.et);
    btnQuery = (Button) findViewById (R.id.btn);
    btnQuery.setOnClickListener(this);
}


@Override
public void onClick(View v){

    if(v.getId() == R.id.btn){
        Toast.makeText(this, "Query submitted", Toast.LENGTH_LONG).show();

        Getdata getdata = new Getdata();
        String returned = null;
        String searchTerm = etQuery.getText().toString();
        try {
            returned = getdata.getInternetData(searchTerm);
        } catch (Exception e) {
            e.printStackTrace();
        }

        try{
            JSONObject jo = new JSONObject(returned);
            JSONArray ja = jo.getJSONArray("results");
            for(int i=0; i<ja.length(); i++){
                JSONObject job = ja.getJSONObject(i);
                Tweet tt = new Tweet();
                tt.username = job.getString("from_user");
                tt.message = job.getString("text");
                tt.image_url = job.getString("profile_image_url");
                tweets.add(tt);
            }
        }
        catch(JSONException e){
            Log.e("log_tag", "Error parsing data: "+e.toString());
        }

        ListView lv = (ListView) findViewById(R.id.listView1);

        class FancyAdapter extends ArrayAdapter<Tweet> {

            public FancyAdapter() {
                super(TwitterSActivity.this, android.R.layout.simple_list_item_1, tweets);
            }

            public View getView(int position, View convertView, ViewGroup parent){
                ViewHolder holder;
                if(convertView == null){
                    LayoutInflater inflater = getLayoutInflater();
                    convertView = inflater.inflate(R.layout.listitem, null);
                    holder = new ViewHolder(convertView);
                    convertView.setTag(holder);
                }
                else
                {
                    holder = (ViewHolder)convertView.getTag();
                }
                holder.populatefrom(tweets.get(position));
                return(convertView);
            }


            class ViewHolder {
                public TextView username = null;
                public TextView message = null;
                public ImageView image = null;

                ViewHolder(View listitem){
                    username = (TextView)listitem.findViewById(R.id.username);
                    message = (TextView)listitem.findViewById(R.id.message);
                    image = (ImageView)listitem.findViewById(R.id.avatar);
                }

                void populatefrom(Tweet t){
                    username.setText(t.username);
                    message.setText(t.message);
                    image.setImageBitmap(getBitmap(t.image_url));
                }
            }
        }

        FancyAdapter ar = new FancyAdapter();
        lv.setAdapter(ar);

    }
}

public Bitmap getBitmap(String bitmapUrl) {
    try {
        URL url = new URL(bitmapUrl);
        return BitmapFactory.decodeStream(url.openConnection().getInputStream()); 
    }
    catch(Exception e) {return null;}
}`
  • 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-03T19:59:27+00:00Added an answer on June 3, 2026 at 7:59 pm

    Finally i figure it out, here is how I fix it:
    I change ArrayList<Tweet> tweets = new ArrayList<Tweet>(); to final ArrayList<Tweet> tweets = new ArrayList<Tweet>();
    and then move it under onClick() method. It works well without notifyDataSetChanged().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building an Android app that resizes based on the screen size using different
I am building an app for Android 2.1 that provides notifications based on calendar
i am building an app based on SEEK for Android. I am facing illegalaccesserror
I'm building an android app where I basically implement a music player from a
As part of an Android App I am building a button set. The buttons
I'm building an Android application that's based around an enhanced WebView (based on PhoneGap).
I'm building an Android app and I need to have two different themes for
We are looking at building a cross-platform mobile app for iPhone, Android, etc. In
I'm building an Android app that is basically an RSS reader, with different topics
We are building a PhoneGap app (both for iOS and Android) that has a

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.