1)下面的代碼:當我輸入autocompletetextview時getView不會被調用。當心片段中的列表和適配器類擴展列表android arrayAdapter with autocomletetextview does not with List <...>
public class SigninFragment extends Fragment {
private List<Test> list= null;
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Test tes= new Test();
tes.setId(1);
tes.setDesc("descabc");
list= new ArrayList<>();
list.add(prof);
tesListAdapter =
new TesListAdapter(
rootView.getContext()
,R.layout.list_row_adapter
,list);
autocompletetextview.setThreshold(3);
autocompletetextview.setAdapter(tesListAdapter);
我的適配器類別:
public class ProfissoesListAdapter extends ArrayAdapter<Test> { **<==HERE**
private LayoutInflater inflater;
private int resource;
public TesListAdapter(Context activity, int resource, List<Test> listaProf) **<==HERE**{
super(activity, resource, listaProf);
this.inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.resource = resource;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
...
2)下面的代碼:YES ...當我輸入autocompletetextview時getView()會被調用。注意在片段中的String []數組和適配器exteding ArrayAdapter
public class SigninFragment extends Fragment {
private List<Test> list= null;
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
String[] list = {"abcde","bbbbbb","bbbakaka","ccccccc","dddddd"};
tesListAdapter =
new TesListAdapter(
rootView.getContext()
,R.layout.list_row_adapter
,list);
autocompletetextview.setThreshold(3);
autocompletetextview.setAdapter(tesListAdapter);
我的適配器類別:
public class ProfissoesListAdapter extends ArrayAdapter<String> { **<==HERE**
private LayoutInflater inflater;
private int resource;
public TesListAdapter(Context activity, int resource, String[] listaProf) { **<==HERE**
super(activity, resource, listaProf);
this.inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.resource = resource;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
...
問題:爲什麼1)選項當我在自動完成textview中鍵入匹配值時,不會在適配器類中調用我的getView? thx
多數民衆贊成它。我前幾天已經修好了,你是對的。請在此評論框外回覆,以便我可以查看您的答案。 thx – Al2x
這不是對其他問題的評論的原因? – Luksprog
nop。在另一個問題中,我有一個片段類和一個自定義適配器。當我調試適配器時,它無法找到RelativeLayout中的嵌套元素 – Al2x