姬長信(Redy)

ANDROID,从Web服务器解析JSON数据并在ListView上…


我试图从JSON url链接显示JSON结果.目前,当我加载时,它什么都不显示,只是空白页面. This is the source where I got information about JSON.

这是我的代码:

public class DVLAresult extends AppCompatActivity {


    public class DVLAlist extends ListActivity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.content_dvlaresult);


            setListAdapter(new ArrayAdapter(
                    this,android.R.layout.simple_list_item_2,
                    this.populate()));
        }


        private ArrayList populate() {
            ArrayList items = new ArrayList();

            TextView newtext = (TextView) findViewById(R.id.view_number);

            try {
                URL url = new URL
                        ("https://dvlasearch.appspot.com/DvlaSearch?licencePlate=mt09nks&apikey=DvlaSearchDemoAccount");
                HttpURLConnection urlConnection =
                        (HttpURLConnection) url.openConnection();
                urlConnection.setRequestMethod("GET");
                urlConnection.connect();
                // gets the server json data
                BufferedReader bufferedReader =
                        new BufferedReader(new InputStreamReader(
                                urlConnection.getInputStream()));
                String next;
                while ((next = bufferedReader.readLine()) != null) {
                    JSONArray ja = new JSONArray(next);

                    for (int i = 0; i 

这是我的XML文件simple_list_2.xml





    

    

    

... Continue up to text18, because I have 18 fields.


这是主要的XML ListView