Monday, April 8, 2013

[android help] Trouble setting items in AlertDialog with OnClickListener


Change:



b.setItems(types, new OnClickListener){


To



b.setItems(types, new DialogInterface.OnClickListener){


And you will have to split



String[] types = {"1", "2", "3"};


to individual ints, or a CharSequence array.


You probably have an OnClickListener for another normal View in your code somewhere, and have it in your imports. As all OnClickListener classes share the same name, Eclipse auto resolves them all to the currently imported one. You can specify the parent class in such cases.


Additionally, the setItems() method that Eclipse has resolved takes a single int for the first parameter, not a String array. You could use the other setItems() method though, which takes a CharSequence Array. In such a case, change



String[] types = {"1", "2", "3"};


to



CharSequence[] types = {"1", "2", "3"};


.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...