Answer the question
In order to leave comments, you need to log in
How to use String in AlertDialog instead of String[]?
In general, there was a problem, I have an int array, which I convert to a String array using Arrays.toString(); for use in the AlertDialog list. But the dialog itself doesn't want to accept saying it's not an array of String, but just one String.
How to make it suitable for dialogue?
Actually code:
String a = Arrays.toString(stack_data);
String[] test2 = a.substring(1,a.length()-1).split(", ");
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
builder.setTitle("История");
builder.setItems(Arrays.toString(test2), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
}
});
AlertDialog alert = builder.create();
alert.show();
Answer the question
In order to leave comments, you need to log in
builder.setItems(test2,new DialogInterface.OnClickListener() { Like
this. Why are you then converting test2 back to a string is not clear.
Where did you even find that it should convert to String[] ?
package java.util;
public class Arrays {
...
public static java.lang.String toString(boolean[] array) { /* compiled code */ }
public static java.lang.String toString(byte[] array) { /* compiled code */ }
public static java.lang.String toString(char[] array) { /* compiled code */ }
public static java.lang.String toString(double[] array) { /* compiled code */ }
public static java.lang.String toString(float[] array) { /* compiled code */ }
public static java.lang.String toString(int[] array) { /* compiled code */ }
public static java.lang.String toString(long[] array) { /* compiled code */ }
public static java.lang.String toString(short[] array) { /* compiled code */ }
public static java.lang.String toString(java.lang.Object[] array) { /* compiled code */ }
...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question