简体   繁体   中英

Android Spinner Adapter Setting to spinner

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);
}

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM