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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:45:20+00:00 2026-05-28T00:45:20+00:00

I am very much new to android and trying to learn various techniques including

  • 0

I am very much new to android and trying to learn various techniques including Search bar using Edit Text options.
I am currently parsing Twitter using JSON and storing it in a list activity.
Also, implementing is the search bar using EditText option such that when a user enters anything it receives a new arraylist.But somehow it needs to get integrated with TextWatcher and ListActivity.

The actual error received : Create Constructor of TextWatcher.
TwitterFeedAdapter has constructor as public TwitterFeedAdapter(Activity a, int textViewResourceId, ArrayList tweets) but when I get the search values back I use TwitterFeedAdapter as ArrayList but it needs to implement TextWatcher.

Any ideas how can I revert the way I am doing or any better help.

/**TwitterFeedActivity**/

public class TwitterFeedActivity extends Activity implements TextWatcher{

public Bitmap placeholder;

private EditText et;
private ListView listView;

private ArrayList<Tweet> tweets;
private ArrayList<Tweet> array_sort= new ArrayList<Tweet>();
int textLength = 0;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    tweets = getTweets("android", 1);

    listView = (ListView) findViewById(R.id.ListViewId);
    et = (EditText)findViewById(R.id.EditText01);

    listView.setAdapter(new TwitterFeedAdapter(this, R.layout.list_item, tweets));  

    et.addTextChangedListener(new TextWatcher()
    {

        @Override
        public void afterTextChanged(Editable arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1,
                int arg2, int arg3) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onTextChanged(CharSequence arg0, int arg1, int arg2,
                int arg3) {
            // TODO Auto-generated method stub
            textLength = et.getText().length();
            array_sort.clear();

            for (int i = 0; i < tweets.size(); i++)
            {
                if (textLength <= tweets.size())
                {
                    if(et.getText().toString().equalsIgnoreCase((String)((CharSequence) tweets.get(i)).subSequence(0,textLength)))
                        {
                         array_sort.add(tweets.get(i));
                         }
                    }
              }
                            /***** Error is here since TwitterFeedAdapter has Activity implemented for it *******/
            listView.setAdapter(new TwitterFeedAdapter(this, R.layout.list_item array_sort));
            }
        });

}

public ArrayList<Tweet> getTweets(String searchTerm, int page) {
    String searchUrl = "http://search.twitter.com/search.json?q=@" 
                        + searchTerm + "&rpp=100&page=" + page;

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

    HttpClient client = new  DefaultHttpClient();
    HttpGet get = new HttpGet(searchUrl);

    ResponseHandler<String> responseHandler = new BasicResponseHandler();

    String responseBody = null;
    try{
        responseBody = client.execute(get, responseHandler);

    }catch(Exception ex) {
        ex.printStackTrace();
    }

    JSONObject jsonObject = null;
    JSONParser parser=new JSONParser();

    try {
        Object obj = parser.parse(responseBody);
        jsonObject=(JSONObject)obj;

    }catch(Exception ex){
        Log.v("TEST","Exception: " + ex.getMessage());
    }

    JSONArray arr = null;

    try {
        Object j = jsonObject.get("results");
        arr = (JSONArray)j;
        System.out.println(arr + "Array");
    }catch(Exception ex){
        Log.v("TEST","Exception: " + ex.getMessage());
    }

    for(Object t : arr) {
        Tweet tweet = new Tweet(
                ((JSONObject)t).get("from_user").toString(),
                ((JSONObject)t).get("text").toString(),
                ((JSONObject)t).get("profile_image_url").toString()
                );
        tweets.add(tweet);
    }

    return tweets;
}   

/** Classes **/

public class Tweet {
    public String username;
    public String message;
    public String image_url;
    public Boolean usernameSet = false;
    public Boolean messageSet = false;
    public Boolean imageSet = false;
    public Bitmap avatar;

    public Tweet(String username, String message, String url) {
        this.username = username;
        this.message = message;
        this.image_url = url;
    }
}
 }

/**TwitterFeedAdapter.java****/

public class TwitterFeedAdapter extends ArrayAdapter<Tweet> {
private ArrayList<Tweet> tweets;
private Activity activity;
public ImageManager imageManager;

public TwitterFeedAdapter(Activity a, int textViewResourceId, ArrayList<Tweet> tweets) {
    super(a, textViewResourceId, tweets);
    this.tweets = tweets;
    activity = a;

    imageManager = new ImageManager(activity.getApplicationContext());
}

public static class ViewHolder{
    public TextView username;
    public TextView message;
    public ImageView image;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    ViewHolder holder;
    if (v == null) {        
        LayoutInflater vi = 
            (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.list_item, null);
        holder = new ViewHolder();
        holder.username = (TextView) v.findViewById(R.id.username);
        holder.message = (TextView) v.findViewById(R.id.message);
        holder.image = (ImageView) v.findViewById(R.id.avatar);
        v.setTag(holder);
    }
    else
        holder=(ViewHolder)v.getTag();

    final Tweet tweet = tweets.get(position);
    if (tweet != null) {
        holder.username.setText(tweet.username);
        holder.message.setText(tweet.message);
        holder.image.setTag(tweet.image_url);
        imageManager.displayImage(tweet.image_url, activity, holder.image);
    }
    return v;
}

}

  • 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-05-28T00:45:21+00:00Added an answer on May 28, 2026 at 12:45 am

    Where you are setting the adapter try changing this to TwitterFeedActivity.this as follows…

    listView.setAdapter(new TwitterFeedAdapter(TwitterFeedActivity.this, R.layout.list_item, array_sort));
    

    EDIT: Also your code is missing a comma between R.layout.list_item and array_sort. I’ve added it to my example above.

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

Sidebar

Related Questions

How to register a new MIME type in android? I am very much new
Possible Duplicate: Android FTP Library I am very much new to the android development,
I am very much new to cocos2d.. I am developing an application in android
I'm very new to Android programming and I've been trying to figure out why
I am very much new to the Continous Integration. Could anyone please let me
I'm very much new to programming and have been doing fairly well so far.
Im new to programming and I dont know very much about but I'm making
Ok, so I am very new to android but I have some experience with
I everyone. I'm very new to Android development and I want to develop an
I am very new to Android programming, and I have read everywhere and I

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.