Possibly a noob question but hopefully I can learn how to do this for the future as well.
可能是一个菜鸟问题,但希望我也能学会如何做到这一点。
I've connected to a mysql database on my server, connects fine, everything works. The problem is I don't know how to get that data into a table for me to use in the layout (Is a tablelayout the best way? I don't want it to fill up an entire layout, I want to be able to add text above the table and below). The code below prints the data into the logcat. You can see for yourself, it's quite basic. I've been learning to do this via various tutorials. Obviously it's not what I want though.
我已连接到我的服务器上的mysql数据库,连接正常,一切正常。问题是我不知道如何将这些数据放入表*我在布局中使用(表格布局是最好的方法吗?我不希望它填满整个布局,我希望能够在表格下方添加文字)。下面的代码将数据打印到logcat中。你可以亲眼看看,这是非常基本的。我一直在学习通过各种教程来做到这一点。显然,这不是我想要的。
Does anyone have any advice on what code I should be putting here so that I can actually use my data once the app has received it. It's already in the JSON format as you can see below. The code below works, it's just not what I want it to do. The tutorials I've seen have implemented the HTTP connection and use ArrayAdaptors together but I've already done the HTTP POST bit and don't want to change it since it took me ages.
有没有人对我应该放在哪里的代码有任何建议,以便我可以在应用程序收到后实际使用我的数据。它已经是JSON格式,如下所示。下面的代码有效,它不是我想要它做的。我见过的教程已经实现了HTTP连接并一起使用了ArrayAdaptors,但我已经完成了HTTP POST位,并且不想更改它,因为它花了我很长时间。
// PARSE STRING
try {
jArray = new JSONArray(result);
JSONObject json_data = null;
System.out.println("Length " + jArray.length());
Log.d("DB", "Length " + jArray.length());
for (int i = 0; i < jArray.length(); i++) {
json_data = jArray.getJSONObject(i);
drivername = json_data.getString("Driver_full_name");
drivesfor = json_data.getString("Drives_for");
System.out.println(drivername + "&" + drivesfor);
}
} catch (JSONException e1) {
Log.d("DB", "Error somewhere");
CurrentSeasonDrivers.this.runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(CurrentSeasonDrivers, "Could not convert data to string", Toast.LENGTH_LONG).show(); } });
}
Any advice is appreciated! My full code including the HTTP connection to show you how I've set things up: http://pastebin.com/MsKc1xPg
任何建议表示赞赏!我的完整代码包括HTTP连接,向您展示我如何设置:http://pastebin.com/MsKc1xPg
1 个解决方案
#1
0
If you got tabular data with common schema, you may want to use ListView to display it. Each row can be literally whatever you want and using ListView automatically solves your problem is you got more rows of data to display. And HTTP POST got nothing do to with it at all. Once you got your data it is irrelevant where it came from. Put it in database, put it in array, ArrayList etc. And display. ListView may be the way.
如果您使用通用架构获得表格数据,则可能需要使用ListView来显示它。每行都可以实际上满足您的需求,使用ListView自动解决您的问题是您需要显示更多行数据。并且HTTP POST根本没有做任何事情。获得数据后,它与来源无关。把它放在数据库中,把它放在数组,ArrayList等中并显示。 ListView可能就是这样。
#1
0
If you got tabular data with common schema, you may want to use ListView to display it. Each row can be literally whatever you want and using ListView automatically solves your problem is you got more rows of data to display. And HTTP POST got nothing do to with it at all. Once you got your data it is irrelevant where it came from. Put it in database, put it in array, ArrayList etc. And display. ListView may be the way.
如果您使用通用架构获得表格数据,则可能需要使用ListView来显示它。每行都可以实际上满足您的需求,使用ListView自动解决您的问题是您需要显示更多行数据。并且HTTP POST根本没有做任何事情。获得数据后,它与来源无关。把它放在数据库中,把它放在数组,ArrayList等中并显示。 ListView可能就是这样。