Android Spinner Adapter Setting to spinner

无人久伴 提交于 2019-12-30 07:54:11

问题


I'm using eneter framework to process communication in my android application; the problem is when I'm trying to populate a spinner, setting the adapter to the spinner cause an undefined exception

Here the code

public void populateSpinner(TypedResponseReceivedEventArgs<String> arg1){
    List<String> list = new ArrayList<String>();
    String listf = arg1.getResponseMessage();
    //sendToDebug(listf);
    StringTokenizer tokenizer = new StringTokenizer(listf,",");
    while(tokenizer.hasMoreElements()){
        list.add((String)tokenizer.nextElement());
    }
    //EditText text = (EditText)findViewById(R.id.number2EditText);
    //text.setText(list.size());
    //text.setText(listf);
    Spinner forfait = (Spinner)findViewById(R.id.forfaitsSpinner);
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,list);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    forfait.setAdapter(adapter);
}

回答1:


you are passing this in the following piece of code,

 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_spinner_item,list);

Not sure in which block this code lies or which class, but ensure that this refers to ActivityName.class or the context




回答2:


It is most likely because you are using an ArrayAdapter rather than a SpinnerAdapter. ArrayAdapter is an indirect implementer of the SpinnerAdapter interface rather than one which declares that it implements the interface. Check the undefined exception. It is likely telling you that setAdapter(ArrayAdapter) is not defined for Spinner.



来源:https://stackoverflow.com/questions/21021565/android-spinner-adapter-setting-to-spinner

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!