Christian Wibowo
Christian Wibowo

Reputation: 225

Convert from string[] to string Android

How can I convert from String[] to String only? So I can assign orderan to items and i can put it into my listview.

Here's my code.

MyClass class= new MyClass();

String orderan =class.getName();
String[] items = orderan; **the problem here

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

        list.setAdapter(adapter);

Upvotes: 0

Views: 83

Answers (3)

Paul D&#39;Ambra
Paul D&#39;Ambra

Reputation: 7814

You have to create an Array and add the string to it.

String[] items = new String[1];
items[0] = orderan;

you can do it in one line

String[] items = {orderan};

Upvotes: 0

Sam
Sam

Reputation: 86948

It appears that you simply want this:

String orderan = class.getName();
String[] items = {orderan};

Or even:

String[] items = {class.getName()};

Upvotes: 1

user462356
user462356

Reputation:

ArrayAdapter wants an array, but you're trying to assign the string orderan into the array items. Instead, make a new array, and add orderran into it. Something like:

String[] items = new String[1];
items[0] = orderan;

Upvotes: 0

Related Questions