public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Button Get_Btn;
private Button Post_Btn;
private Button Image_Btn;
private ImageView get_Image;
private String mUrl = "http://112.124.22.238:8081/course_api/cniaoplay/featured2?p={%27page%27:0}";
private String mPostUrl = "http://172.16.45.10:8080/FuWebDemo/AA";
private TextView mText;
private NetworkImageView mNet;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
private void initView() {
Get_Btn = (Button) findViewById(R.id.Get_Btn);
Post_Btn = (Button) findViewById(R.id.Post_Btn);
Image_Btn = (Button) findViewById(R.id.Image_Btn);
get_Image = (ImageView) findViewById(R.id.get_Image);
mText = (TextView) findViewById(R.id.Get_Text);
Get_Btn.setOnClickListener(this);
Post_Btn.setOnClickListener(this);
Image_Btn.setOnClickListener(this);
mNet = (NetworkImageView) findViewById(R.id.NetImage);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.Get_Btn:
getInfo();
break;
case R.id.Post_Btn:
postInfo();
break;
case R.id.Image_Btn:
// getImage();
// getImageLoader();
getNetImage();
break;
}
}
//get请求数据
private void getInfo() { RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this); StringRequest stringRequest = new StringRequest(StringRequest.Method.GET, mUrl, new Response.Listener() {
@Override
public void onResponse(String response) {
mText.setText(response + "");
}
}, null);
requestQueue.add(stringRequest);
}