3

je dois montrer deux sections en AutoCompleteTextView (quelque chose comme ça):Comment remplir des données dans AutoCompleteTextView?

enter image description here

J'ai créé un custom layout qui ont deux CardViews et chaque CardView ont trois TextViews. En ce moment je ne distribue pas la section sur la base de type. L'ensemble des données est chargé dans une section.

Activité

final AutocompleteLocalityAdapter adapterLocalities = new AutocompleteLocalityAdapter(context, 
       R.layout.support_simple_spinner_dropdown_item, new ArrayList<Locality>()); 

AutocompleteLocalityAdapter

public class AutocompleteLocalityAdapter extends ArrayAdapter<Locality> { 
public AutocompleteLocalityAdapter(Context context, int layout, List<Locality> localities) { 
    super(context, layout, localities); 
    this.localities = localities; 
    updateList(""); 
} 

Dans updateList méthode que je fais un nouvel appel de réseau pour remplir les données Locality classe.

Que dois-je faire pour classer les résultats de la recherche par image donnée? ArrayAdapter ne va pas travailler ici à coup sûr. La solution possible que je pense ici est: Remplacer ArrayAdapter à RecyclerViewAdapter.

Tout indice sera appréciable.

+0

cochez cette case (http://stackoverflow.com/a/9906539/3746306) –

+0

@ndeokar Comment cela va-t-il m'aider? –

+0

J'ai une facilité de tri donc pensé que cela aiderait –

Répondre

1

L'improvisation possible à cette solution est PopUpWindow. À l'intérieur du PopUpWindow j'ai mis deux RecyclerView et les peupler par des appels de réseau.

dashboard_profile_popup_window

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:layout_margin="@dimen/margin_low" 
android:orientation="vertical"> 

<android.support.v7.widget.CardView 
    android:id="@+id/locationCardView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:elevation="@dimen/corner_radius" 
    app:cardUseCompatPadding="true"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/landmark" 
      android:textStyle="bold" /> 

     <ListView 
      android:id="@+id/localityView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

    </LinearLayout> 
</android.support.v7.widget.CardView> 


<android.support.v7.widget.CardView 
    android:id="@+id/landmarkCardView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:elevation="@dimen/corner_radius" 
    app:cardUseCompatPadding="true"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/location" 
      android:textStyle="bold" /> 

     <ListView 
      android:id="@+id/landmarkView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 
    </LinearLayout> 

</android.support.v7.widget.CardView> 

CustomWidget

public class CustomAutoCompleteView extends EditText { 
private Context context; 
TextListViewAdapter locationAdapter; 
TextListViewAdapter landmarkAdaper; 
PopupWindow pwindow; 
ClickListener clickListener; 

public CustomAutoCompleteView(Context context) { 
    super(context); 
    this.context = context; 
    setCustomization(); 
} 

public void closeWindow(){ 
    pwindow.dismiss(); 
} 

public CustomAutoCompleteView(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    this.context = context; 
    setCustomization(); 
} 

public CustomAutoCompleteView(Context context, AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
    this.context = context; 
    setCustomization(); 
} 

public void updateList(List<LocalityEntity> locationList, List<LocalityEntity> landmarkList) { 
    if (pwindow == null) { 
     initPopupWindow(); 
    } 
    locationAdapter.updateList(locationList); 
    landmarkAdaper.updateList(landmarkList); 
} 

public void initPopupWindow() { 
    LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View layout = layoutInflater.inflate(R.layout.dashboard_profile_popup_window, null); 

    ListView landmarkRecyclerView = (ListView) layout.findViewById(R.id.localityView); 
    ListView localityRecyclerView = (ListView) layout.findViewById(R.id.landmarkView); 
    landmarkRecyclerView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
     @Override 
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
      String text = ((TextView) view.findViewById(R.id.localityText)).getText().toString(); 
      String gid = ((TextView) view.findViewById(R.id.localityGID)).getText().toString(); 
      clickListener.placeSelected(gid); 
     } 
    }); 
    localityRecyclerView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
     @Override 
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
      String text = ((TextView) view.findViewById(R.id.localityText)).getText().toString(); 
      String gid = ((TextView) view.findViewById(R.id.localityGID)).getText().toString(); 
      clickListener.placeSelected(gid); 
     } 
    }); 
    landmarkRecyclerView.setAdapter(landmarkAdaper); 
    localityRecyclerView.setAdapter(locationAdapter); 

    pwindow = new PopupWindow(context); 
    pwindow.setContentView(layout); 
    pwindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); 
    pwindow.setWidth(this.getWidth()); 
    pwindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); 
    pwindow.setFocusable(true); 
    pwindow.setOnDismissListener(new PopupWindow.OnDismissListener() { 

     @Override 
     public void onDismiss() { 
      pwindow = null; 
     } 

    }); 
    pwindow.showAsDropDown(this); 
} 

private void setCustomization() { 
    locationAdapter = new TextListViewAdapter(getContext()); 
    landmarkAdaper = new TextListViewAdapter(getContext()); 
    initPopupWindow(); 

} 

public void setClickListener(ClickListener clickListener) { 
    this.clickListener = clickListener; 
} 

public interface ClickListener { 
    void placeSelected(String gid); 
} 
} 

appellent maintenant ce customViewWidget par le code suivant:

place_pop_up.setClickListener(this); 
place_pop_up.addTextChangedListener(new TextWatcher() { 
@Override 
public void beforeTextChanged(CharSequence s, int start, int count, int after) { 
    } 

@Override 
public void onTextChanged(CharSequence s, int start, int before, int count) { 
} 

    private Timer timer = new Timer(); 
     private final long DELAY = 2000; 

     @Override 
     public void afterTextChanged(final Editable s) { 
      if (s.length() > 3) { 
       timer.cancel(); 
       timer = new Timer(); 
       timer.schedule(new TimerTask() { 
        @Override 
        public void run() { 
         getAutoCompleteSearchResult(s.toString()); 
        } 
       }, DELAY); 
      } 
     } 
    }); 

En getAutoCompleteSearchResult effectuer l'appel réseau et appeler place_pop_up.updateList(locality, landmark);