XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity"
android:background="#FFFFFF"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="10dp"
>
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Click"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#E91E63"
android:backgroundTint="#3F51B5"
android:layout_marginTop="50dp"
/>
<TextView
android:id="@+id/tName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#000000"
android:layout_below="@+id/button"
android:layout_marginTop="10dp"
/>
<TextView
android:id="@+id/Tl1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#000000"
android:layout_below="@+id/tName"
android:layout_marginTop="10dp"
android:background="#FFC107"
/>
<TextView
android:id="@+id/tMobile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Mobile"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#000000"
android:layout_below="@+id/Tl1"
android:layout_marginTop="10dp"
/>
<TextView
android:id="@+id/Tl2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#000000"
android:layout_below="@+id/tMobile"
android:layout_marginTop="10dp"
android:background="#FFC107"
/>
<TextView
android:id="@+id/tEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Mobile"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#000000"
android:layout_below="@+id/Tl2"
android:layout_marginTop="10dp"
/>
<TextView
android:id="@+id/Tl3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#000000"
android:layout_below="@+id/tEmail"
android:layout_marginTop="10dp"
android:background="#FFC107"
/>
<TextView
android:id="@+id/tAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Mobile"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#000000"
android:layout_below="@+id/Tl3"
android:layout_marginTop="10dp"
/>
<TextView
android:id="@+id/Tl4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#000000"
android:layout_below="@+id/tAddress"
android:layout_marginTop="10dp"
android:background="#FFC107"
/>
</LinearLayout>
</RelativeLayout>
JAVA
package com.rakibshah.server;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
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 {
Button button;
TextView tName,Tl1,tMobile,Tl2,tEmail,Tl3,tAddress,Tl4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = findViewById(R.id.button);
tName = findViewById(R.id.tName);
Tl1 = findViewById(R.id.Tl1);
tMobile = findViewById(R.id.tMobile);
Tl2 = findViewById(R.id.Tl2);
tEmail = findViewById(R.id.tEmail);
Tl3 = findViewById(R.id.Tl3);
tAddress = findViewById(R.id.tAddress);
Tl4 = findViewById(R.id.Tl4);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Instantiate the RequestQueue.
RequestQueue queue = Volley.newRequestQueue(MainActivity.this);
String url = "https://asoshikhi.com/Drive/job.json";
// 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.
button.setText("Response is: " + response.substring(0,500));
Log.d("serverRes",response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
button.setText("That didn't work!");
}
});
// Add the request to the RequestQueue.
queue.add(stringRequest);
}
});
}
}MANIFEST<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>BUILS GRADLEimplementation libs.volley
No comments:
Post a Comment