English 中文(简体)
Android: 从 Mysql 检索数据
原标题:Android: retrieving data from mysql

我一直在编译 PHP, 但学习如何构建一个机器人应用程序。 在 PHP 中, 我从 Mysql 中检索到数据, 然后通过将数据设置为变量来设计我的网络布局...

$name = $SQL["name"];

类似的东西,然后我可以玩弄HTML。我知道,机器人完全不同, 但我想知道,如果有人能解释 我需要了解的是什么, 或者有例子表明,我可以随便设计一个不错的UI。

我现在有这个:

try {
            JSONArray jArray = new JSONArray(result);
            int jArrayLength = jArray.length();
            List<String> listContents = new ArrayList<String>(jArrayLength);

            for(int i =0; i<jArray.length(); i++){
                JSONObject json_data = jArray.getJSONObject(i);
                listContents.add(json_data.getString("full_name"));
            }

            ListView myListView = (ListView) findViewById(R.id.front_page_listview);
            myListView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listContents));

        }catch(JSONException e){
            Log.e("log_tag","Error parsin data "+e.toString());
}

何处处

listContents.add(json_data.getString("full_name"));

显示全名, 但如果我想添加更多信息, 比如电子邮件、 电话号码、 文本等 。

如果我这样做:

listContents.add(json_data.getString("full_name"));
listContents.add(json_data.getString("email"));

它只是要给另一个行, 但我希望名字和电子邮件 在同一行, 我想能够设计这行我自己,

有什么想法吗?

谢谢!

问题回答

您可以制作自定义的适配器和自定义的行布局。 然后, 您可以对您想要的布局进行引用 。 适配器可以来自您的 JSONObject 数组 - jAray, 保存您想要显示的所有数据。 然后, 在获取方法中, 它会向自定义视图充气, 并将所有您想要的数据放入它 。

对不起,如果这还不够清楚。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签