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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:46:12+00:00 2026-06-11T07:46:12+00:00

I would use AutoCompleteTextView using data from web-service-rest.The difficulty lies in using a ArrayAdapter

  • 0

I would use AutoCompleteTextView using data from web-service-rest.The difficulty lies in using a ArrayAdapter with ViewHolder.

this is part of my mainActivity.java

final AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
        autoCompleteTextView.addTextChangedListener(new TextWatcher() {

            private boolean shouldAutoComplete = false;

            public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
                shouldAutoComplete = true;

            }

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

            }

            public void afterTextChanged(Editable arg0) {
                if(shouldAutoComplete){

                    try {
                        ArrayList<Intervento> interventos = getInterventos(autoCompleteTextView.getText().toString());
                        AutoCompleteAdapter adapter = new AutoCompleteAdapter(MainActivity.this,R.layout.suggest_list,interventos);
                        adapter.setNotifyOnChange(true);
                        autoCompleteTextView.setAdapter(adapter);
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (ExecutionException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                }

            }
        });

this is my custom class AutoCompleteAdapter

    public class AutoCompleteAdapter extends ArrayAdapter<Intervento>  implements Filterable {

    static class ViewHolder{
         private TextView  textName;
         private TextView  textId;
    }

    private ArrayList<Intervento> arrayListIntervento;
    private int              layout;


    @Override
      public int getCount() {
        return arrayListIntervento.size();
      }

    @Override
    public Intervento getItem(int index) {
        return arrayListIntervento.get(index);
    }


     @Override
        public Filter getFilter() {
         Filter myFilter = new Filter() {
                @Override
                protected void publishResults(CharSequence contraint, FilterResults results) {
                    if(results != null && results.count > 0) {
                    notifyDataSetChanged();
                    }
                    else {
                        notifyDataSetInvalidated();
                    }
                }

                @Override
                protected FilterResults performFiltering(CharSequence arg0) {
                    FilterResults filterResults = new FilterResults();
                    if(arg0 != null) {
                        try {
                            arrayListIntervento = new InterventoController().execute("http://192.168.1.162:8080/******/******/{*******}/****/**********", arg0.toString()).get();
                        }
                        catch(Exception e) {
                            e.printStackTrace();
                        }
                        // Now assign the values and count to the FilterResults object
                        filterResults.values = arrayListIntervento;
                        filterResults.count = arrayListIntervento.size();
                    }
                    return filterResults;
                }
            };
            return myFilter;
     }




    @Override
    public View getView(int position, View contentView, ViewGroup viewGroup) {

        View       view = null;
        ViewHolder viewHolder = null;

        if(contentView==null){
            LayoutInflater inflater =  (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(R.layout.suggest_list, null);

            if (view != null) {
                viewHolder = new ViewHolder();
                viewHolder.textId = (TextView) view.findViewById(R.id.idIntervento);
                viewHolder.textName = (TextView) view.findViewById(R.id.nomeIntervento);
                view.setTag(viewHolder);
            }
        }else {
            view = contentView;
            viewHolder = (ViewHolder) contentView.getTag();
        }

        if (viewHolder != null) {
            Intervento intervento = arrayListIntervento.get(position);
            if(intervento!=null){
                viewHolder.textId.setText(intervento.getIdintervento().toString());
                viewHolder.textId.setVisibility(View.INVISIBLE);
                viewHolder.textName.setText(intervento.getNome());
            }
        }

        return view;

    }

    public AutoCompleteAdapter(Context context, int textViewResourceId) {
        super(context, textViewResourceId);

        this.arrayListIntervento= new ArrayList<Intervento>();
        this.layout=textViewResourceId;
    }


}

and this is my custom layout for listing suggestion

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <TextView
            android:id="@+id/nomeIntervento"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:text="@string/autocompleteIntervento" />

        <TextView
            android:id="@+id/idIntervento"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:text="@string/autocompleteIntervento" />


    </RelativeLayout>

I can get the data but I do not are shown on the screen. Where is the problem?
thanks in advance!

  • 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-11T07:46:14+00:00Added an answer on June 11, 2026 at 7:46 am

    Hey you just missed implementing Filterable.

    Use this as your reference.
    Hope this will help you.

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

Sidebar

Related Questions

I am wondering what I would use to grab data from a form as
I would use an expression like this $(a[href*='2']).offset().left but for iframe's elements ... I
I would use hg4idea to do this but it seems to leak memory badly.
normally I would use Python/Perl for this procedure but I find myself (for political
In a .jsp I would use: <fmt:message key=welcome.title/> to display a message from my
To get field names one would use the command: select column_name from information_schema.columns where
În php I would use this to see if a variable is set and
I have a program which would use the Application Role to write data to
I would use telnet to send a simple string to an active service that
I had thought I would use curl for this but it looks like 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.