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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:40:26+00:00 2026-06-10T04:40:26+00:00

I have implemented a Custom List View which displays text along with image. The

  • 0

I have implemented a Custom List View which displays text along with image. The List View fetches data from XML data present over the internet. When the user scrolls down, more data is loaded into the application. Now, I am trying to include a search bar so that when the user searches for some data, the application displays the results returned by the search. The main problem is that the list view doesn’t show the correct data when search is performed.

When I check the URL that is being executed by the Search bar in a browser, it shows the correct results, but in Android application it behaves differently.

Below is the code of my Activity that performs this whole work:-

public class OrganizationActivity extends Activity implements OnScrollListener {

int itemsPerPage = 10;
boolean loadingMore = false;
int mPos=0;

// All static variables
static final String URL = "some URL";
static int page_no = 1;

// XML node keys
static final String KEY_ORGANIZATION = "organization"; // parent node
static final String KEY_ID = "id";
static final String KEY_NAME = "name";
static final String KEY_CITY = "city";
static final String KEY_STATE = "state";
static final String KEY_IMAGE_URL = "image";

ListView list;
LazyAdapter adapter;
ArrayList<HashMap<String, String>> orgsList = new ArrayList<HashMap<String, String>>();
private EditText filterText = null;

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

    filterText = (EditText) findViewById(R.id.search_box_et);
    filterText.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
            if(arg0.length()==0)
            {
                list.setAdapter(new LazyAdapter(OrganizationActivity.this, orgsList));
            }
            list.setAdapter(new LazyAdapter(OrganizationActivity.this, orgsList));
            String searchtext = null;
            try {
                searchtext=URLEncoder.encode(arg0.toString().trim(),"UTF-8");
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            String urlStr = "myURL?search="+searchtext;
            new LoadData().execute(urlStr);
            adapter = new LazyAdapter(OrganizationActivity.this, orgsList);
            list.setAdapter(adapter);
        }

    });

    XMLParser parser = new XMLParser();
    String xml = parser.getXmlFromUrl(URL); // getting XML from URL
    Document doc = parser.getDomElement(xml); // getting DOM element

    NodeList nl = doc.getElementsByTagName(KEY_ORGANIZATION);
    // looping through all organization nodes <organization>
    for (int i = 0; i < nl.getLength(); i++) {
        // creating new HashMap
        HashMap<String, String> map = new HashMap<String, String>();
        Element e = (Element) nl.item(i);
        // adding each child node to HashMap key => value
        map.put(KEY_ID, parser.getValue(e, KEY_ID));
        map.put(KEY_NAME, parser.getValue(e, KEY_NAME));
        map.put(KEY_CITY, parser.getValue(e, KEY_CITY));
        map.put(KEY_STATE, parser.getValue(e, KEY_STATE));
        map.put(KEY_IMAGE_URL, parser.getValue(e, KEY_IMAGE_URL));

        // adding HashList to ArrayList
        orgsList.add(map);
    }

    list = (ListView) findViewById(R.id.list);

    View footerView = ((LayoutInflater) this
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(
            R.layout.listfooter, null, false);
    list.addFooterView(footerView);

    // Getting adapter by passing xml data ArrayList
    adapter = new LazyAdapter(this, orgsList);
    list.setAdapter(adapter);
    list.setOnScrollListener(this);

    // Click event for single list row
    list.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

            String name = orgsList.get(position).get(KEY_NAME).toString();
            Toast.makeText(getApplicationContext(), name, Toast.LENGTH_LONG)
                    .show();
        }
    });

}


private class LoadData extends AsyncTask<String, Void, String> {

    @Override
    protected String doInBackground(String... urls) {

        for (String url : urls) {
            // TODO Auto-generated method stub
            XMLParser parser = new XMLParser();
            String xml = parser.getXmlFromUrl(url); // getting XML from URL
            Document doc = parser.getDomElement(xml); // getting DOM element

            NodeList nl = doc.getElementsByTagName(KEY_ORGANIZATION);
            // looping through all organization nodes <organization>
            for (int i = 0; i < nl.getLength(); i++) {
                // creating new HashMap
                HashMap<String, String> map = new HashMap<String, String>();
                Element e = (Element) nl.item(i);
                // adding each child node to HashMap key => value
                map.put(KEY_ID, parser.getValue(e, KEY_ID));
                map.put(KEY_NAME, parser.getValue(e, KEY_NAME));
                map.put(KEY_CITY, parser.getValue(e, KEY_CITY));
                map.put(KEY_STATE, parser.getValue(e, KEY_STATE));
                map.put(KEY_IMAGE_URL, parser.getValue(e, KEY_IMAGE_URL));

                // adding HashList to ArrayList
                orgsList.add(map);
            }
        }
        return null;
    }

    @Override
    protected void onPostExecute(String result) {
        // TODO Auto-generated method stub
        adapter = new LazyAdapter(OrganizationActivity.this, orgsList);
        list.setAdapter(adapter);
        list.setSelectionFromTop(mPos, 0);
    }
}

@Override
public void onScroll(AbsListView view, int firstVisibleItem,
        int visibleItemCount, int totalItemCount) {

    //Get the visible item position
    mPos=list.getFirstVisiblePosition();

    int lastInScreen = firstVisibleItem + visibleItemCount;

    //Is the bottom item visible & not loading more already? Load more !
    if ((lastInScreen == totalItemCount) && !(loadingMore)) {
        page_no++;
        String pageURL = "myURL?page="
                + page_no;
        new LoadData().execute(pageURL);
    }

}

@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
    // TODO Auto-generated method stub

}

}

Please help me out in finding the solution to this problem…

  • 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-10T04:40:28+00:00Added an answer on June 10, 2026 at 4:40 am

    Looks like I was doing little bit of mistake in refreshing my ListView with the new data and also I was calling the notifyDataSetListener somewhere else. Now it is working absolutely fine..

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

Sidebar

Related Questions

I have implemented a custom list view which looks like the twitter timeline. adapter
I have implemented a custom ActionMapper which obtains the locale from the URI (the
I have implemented a custom view within another activity into a XML layout. The
In my WCF service I have implemented a custom encoder which inherits from System.ServiceModel.Channels.MessageEncoder
I have a custom control that is derived from ListView . This list view
In my application i have used list view and custom cell which contain product
I have created a custom annotation view. In the setSelected method i have implemented
I have implemented a list of users in my Qt program, using the model/view
I have an activity with a listview in it. I implemented a custom list
I'm trying to implement a custom validation annotation in Seam. We have a list

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.