0

В принципе, я хочу что-то написать в edittext, тогда будет вызываться веб-http-запрос, который возвращает JSONObject, который содержит массив JSON, который содержит значения где-то внутри него. Мне нужно, чтобы populat выпадающий список, который поставляется с autocompletetextview с результатами из объекта JSON.Android Custom AutoCompleteTextView с пользовательским адаптером

Я могу сделать второй бит, то есть я могу заполнить выпадающий список со значениями, которые мне нужны, используя специальный класс адаптера, который расширяет массив, как вы можете видеть ниже. Моя проблема связана с первым битом, как я могу переопределить AutoCompleteTextView таким образом, чтобы он не показывал мне фильтрованные постоянные значения из массива, а показывает мне значения, которые я им даю? Я не хочу, чтобы он был фильтруемым вообще. Вот исходный код для AutoCompleteTextView http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.4_r2.1/android/widget/AutoCompleteTextView.java#91

public class PersonAdapter extends ArrayAdapter 
{ 

    // we use the constructor allowing to provide a List of objects for the data 
    // to be binded. 
    public PersonAdapter(Context context, int textViewResourceId, 
      List objects) { 
     super(context, textViewResourceId, objects); 
    } 

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

     // retrieve the Person object binded at this position 
     final Person p = getItem(position); 

     // A ViewHolder keeps references to children views to avoid unneccessary 
     // calls 
     // to findViewById() on each row. 
     ViewHolder holder; 

     // When convertView is not null, we can reuse it directly, there is no 
     // need 
     // to reinflate it. We only inflate a new View when the convertView 
     // supplied 
     // by ListView is null. 
     if (convertView == null) { 
      convertView = View.inflate(getContext(), R.layout.list_item, parent, false); 

      // Creates a ViewHolder and store references to the two children 
      // views 
      // we want to bind data to. 
      holder = new ViewHolder(); 
      holder.textName = (TextView) convertView 
        .findViewById(R.id.textName); 
      holder.textEmail = (TextView) convertView 
        .findViewById(R.id.textEmail); 
      holder.picture = (ImageView) convertView.findViewById(R.id.image); 
      holder.picture.setFocusable(false); 
      holder.picture.setFocusableInTouchMode(false); 
      convertView.setTag(holder); 
     } else { 
      // Get the ViewHolder back to get fast access to the TextView 
      // and the ImageView. 
      holder = (ViewHolder) convertView.getTag(); 
     } 

     // Bind the data efficiently with the holder. 
     holder.textName.setText(p.getName()); 
     holder.textEmail.setText(p.getEmail()); 
     holder.picture.setImageResource(p.getResImage()); 
       //click on the picture 
     holder.picture.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Toast.makeText(getContext(), 
         "Clicked on " + p.getName() + "'s picture", 
         Toast.LENGTH_SHORT).show(); 

      } 
     }); 

     return convertView; 
    } 

    /** 
    * 
    * Inner holder class for a single row view in the ListView 
    * 
    */ 
    static class ViewHolder { 
     TextView textName, textEmail; 
     ImageView picture; 
    } 

} 

ответ

2

в вашем PersonAdapter переназначения getFilter() метод, возвращающий свой заказ внутренний фильтр, где вы должны реализовать свои два метода: performFiltering() и publishResults(), performFiltering запускается в рабочий нить, и здесь вы вызываете свой веб-запрос, в publishResults просто наберите clear() и добавьте() элементы

+0

Я действительно сомневаюсь, что это сработает, но я попробую и посмотрю –

+0

, почему это не работает? – pskink

+0

Спасибо, что сделали. Хотя, я получил помощь и от этого вопроса, а также http://stackoverflow.com/questions/5023645/how-do-i-use-autocompletetextview-and-populate-it-with-data-from-a-web-api –

Смежные вопросы