我想从我的PHP页面得到的Integer
值,并插入到Android TextView
例子:我在PHP页面分配“INT水平= 1”和我想的变量“水平”这个值插入到Android TextView
。如何从网页获取变量的值到Android TextView中?
这里的任何人都可以帮我或给我一个教程的链接?
感谢您的帮助。
我想从我的PHP页面得到的Integer
值,并插入到Android TextView
例子:我在PHP页面分配“INT水平= 1”和我想的变量“水平”这个值插入到Android TextView
。如何从网页获取变量的值到Android TextView中?
这里的任何人都可以帮我或给我一个教程的链接?
感谢您的帮助。
final TextView mTextView = (TextView) findViewById(R.id.text); ...
// Instantiate the RequestQueue. RequestQueue queue = Volley.newRequestQueue(this); String url ="http://www.google.com";
// Request a string response from the provided URL. StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// Display the first 500 characters of the response string.
mTextView.setText("Response is: "+ response.substring(0,500));
} }, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
mTextView.setText("That didn't work!");
} }); // Add the requestto the RequestQueue. queue.add(stringRequest);
此代码应该代表您的问题,它可能会有所帮助。如果不是,请查看链接。 来源:https://developer.android.com/training/volley/simple.html
你可以建立或那种方式编码Json
你也将获得,在Android的侧
像KEY
和VALUE
:{ key = values }
其中
key = level(your TABLE column name)
和value = 1
(动态值)如果您想知道如何获得column_name
和编码JSON
按照return JSON from mysql with column name
你的意思是我必须使用Json:php值为Json和Json值为Android?你能否详细介绍一下这方面的细节,因为我对json和android很陌生。 – user3208987
你可以用它的列名将json编码到你的数据库和它的值这就是它 –
在这段代码中,android如何获得变量“level”的值? – user3208987
@ user3208987您可以在php代码中将其回显出来...... <?php echo level; ?> php网站的整个输出将被放入TextView中... – EricHier
哦,我知道了,让我试试。我很快会通知你结果。 – user3208987