-1

I have looked at several discussions on this topics but no conclusive answer has been given. I have an issue, am trying to get data from MySql database into JSON and into Array List, then finally into a String[] which will populate the ListView.

Am trying to Convert an ArrayList to a String[] Array myDataLists Contains all the values picked up from JSON, and dataList is the String Array to populate the ListView using the LazerAdapter.

The Conversion is as follows

String[] dataList = new String[myDataLists.size()];
        dataList = myDataLists.toArray(dataList);

I have tried this and it works properly

String dataList[] = {"Value 1","Value 2", "Value 3"}

However i want the values to come from the db and so I have narrowed down to the problem. Its the String[] Array, it picks the values but may not be registered as a String Array and so it gives a blank String[] Array;

The following is my scenario.

The List Loading

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    new LoadRecentData().execute();

    list=(ListView)findViewById(R.id.listView1);
    adapter=new LazyAdapter(this, dataList);
    list.setAdapter(adapter);
}

What would be the proper way to get the Correct String[] Array that will output

{"Value 1","Value 2", "Value 3"}

4

1 回答 1

0

所以你想stringarray从一个创建一个arrayList

利用String [] dataList = (String[]) myDataLists.toArray(new String[0]);

在这里阅读javadoc

于 2013-09-03T08:30:00.233 回答