Prashant Sontale
Newbie
Java:
package com.example.anitaa.student;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
public class MainActivity extends AppCompatActivity {
TextView text;
Button b1;
String url1="http://192.168.1.3/student/web/index.php?r=message/display";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text=(TextView) findViewById(R.id.text_content);
b1=(Button) findViewById(R.id.btn5);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final RequestQueue requestQueue1= Volley.newRequestQueue(MainActivity.this);
StringRequest stringRequest1=new StringRequest(Request.Method.POST, url1, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
text.setText(response);
requestQueue1.stop();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
text.setText("Error");
error.printStackTrace();
requestQueue1.stop();
}
});
requestQueue1.add(stringRequest1);
}
});
}
}