我想在我的启动画面的文本视图中显示从http://localhost/test/getcontent1.php开始的消息
我写了一个将回显jsno数据的php文件
<?php
$strorg = '[{"code":"101","message":"OK"}]';
$str = json_encode($strorg);
echo $str;
?>
链接的输出是 &#34; [{\&#34;代码\&#34;:\&#34; 101 \&#34; \&#34;消息\&#34;:\&#34; OK \& #34;}]&#34;
我在splashscreen活动中编写了以下代码
public class SplashScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
final TextView mTxtDisplay;
mTxtDisplay = (TextView) findViewById(R.id.txtDisplay);
String url = "http://localhost/test/getcontent1.php";
mTxtDisplay.setText("Begin");
JsonObjectRequest jsObjRequest = new JsonObjectRequest
(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
mTxtDisplay.setText("Response: " + response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
mTxtDisplay.setText(error.toString());
}
});
Thread timerThread = new Thread() {
public void run() {
try {
sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
Intent intent = new Intent(SplashScreen.this, MainActivity.class);
startActivity(intent);
}
}
};
timerThread.start();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
但我没有得到任何回应。 textview只显示BEGIN sombody可以有任何解决方案吗?因为我是android的新手