What I’m doing is building an Android app that receives a string using a php script which I can do, but what I can’t do is then split that string up using the “\n” and then use that to create an AlertDialog.
I’m recieving this string;
String list = "test 1\ntest 2\ntest 3";
I’m then trying to then pipe that into an array using the below. I know I’m miles off but can’t seem to find anything about it, could someone point me in the right direction?
String[] tokens = test.split("\n");
final CharSequence[] items = {tokens};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pick a color");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
}
});
AlertDialog alert = builder.create();
alert.show();
Why are you creating a new array for the CharSequence? You can just set the tokens array as items: