I can do only add jsonobj and json obj like in the left hand side in this picture
but if i want to add data like right hand side what code should i add to my code
(i want to know how to specific the header of json array which i want to add)
(credit code from ThinkTwiceCodeOnce)
my code is ...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
new PostDataTask().execute("http://<myip4:port>/api/status");
}
class PostDataTask extends AsyncTask<String, Void, String> {
ProgressDialog progressDialog;
#Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setMessage("Inserting data...");
progressDialog.show();
}
#Override
protected String doInBackground(String... params) {
try {
return postData(params[0]);
} catch (IOException ex) {
return "Network error !";
} catch (JSONException ex) {
return "Data Invalid !";
}
}
#Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
mResult.setText(result);
if (progressDialog != null) {
progressDialog.dismiss();
}
}
private String postData(String urlPath) throws IOException, JSONException {
StringBuilder result = new StringBuilder();
BufferedWriter bufferedWriter = null;
BufferedReader bufferedReader = null;
try {
//Create data to send to server
JSONObject dataToSend = new JSONObject();
dataToSend.put("name", "puggy");
dataToSend.put("like", "dog");
dataToSend.put("eat", "meat");
dataToSend.put("fav", "red balloon");
//Initialize and config request, then connect to server.
URL url = new URL(urlPath);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setReadTimeout(10000 /* milliseconds */);
urlConnection.setConnectTimeout(10000 /* milliseconds */);
urlConnection.setRequestMethod("POST");
urlConnection.setDoOutput(true); //enable output (body data)
urlConnection.setRequestProperty("Content-Type", "application/json");// set header
urlConnection.connect();
//Write data into server
OutputStream outputStream = urlConnection.getOutputStream();
bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream));
bufferedWriter.write(dataToSend.toString());
bufferedWriter.flush();
//Read data response from server
InputStream inputStream = urlConnection.getInputStream();
bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = bufferedReader.readLine()) != null) {
result.append(line).append("\n");
}
} finally {
if (bufferedReader != null) {
bufferedReader.close();
}
if (bufferedWriter != null) {
bufferedWriter.close();
}
}
return result.toString();
}
}
Use dataToSend.put("profile", JSONArrayProfile) to add profile JSONArray to JSONObject.
Here is the working code. Try this:
try {
JSONObject dataToSend = new JSONObject();
// Profile
JSONArray jsonArrayProfile = new JSONArray();
// Post 1
JSONObject jsonObjectPost1 = new JSONObject();
jsonObjectPost1.put("fbname", "Think Twice Code Once");
jsonObjectPost1.put("content", "felling full");
jsonObjectPost1.put("likes", 1);
jsonObjectPost1.put("comments", 3);
// Post 2
JSONObject jsonObjectPost2 = new JSONObject();
jsonObjectPost2.put("fbname", "Think Twice Code Once");
jsonObjectPost2.put("content", "felling full");
jsonObjectPost2.put("likes", 1);
jsonObjectPost2.put("comments", 3);
// Add post1, post2 jsonObject to profile jsonArray
jsonArrayProfile.put(jsonObjectPost1);
jsonArrayProfile.put(jsonObjectPost2);
// Add profile jsonArray to jsonObject
dataToSend.put("profile", jsonArrayProfile);
Log.d("SUCCESS", "JSON: " + dataToSend.toString());
} catch (final JSONException e) {
Log.e("FAILED", "Json build error: " + e.getMessage());
}
OUTPUT:
{
"profile":[
{
"fbname":"Think Twice Code Once",
"content":"felling full",
"likes":1,
"comments":3
},
{
"fbname":"Think Twice Code Once",
"content":"felling full",
"likes":1,
"comments":3
}
]
}
You can use following code to try it.
JSONArray ja = new JSONArray();
ja.put(dataToSend);
You have to create JSON objects of this way
JSONObject dataToSend = new JSONObject();
JSONArray arrayData = new JSONArray();
dataToSend.put("profile",arrayData);
And if you want to add JSON object to your JSONArray use this
arrayData.put(JSONObject1);
arrayData.put(JSONObject2);
Related
Url
private static String JSON_URL ="https://run.mocky.io/v3/aff3f637-d04f-45c0-b002-09be1a143784";
ArrayList<HashMap<String,String>> friendsList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
friendsList= new ArrayList<>();
lv = findViewById(R.id.listview);
GetData getData= new GetData();
getData.execute();
}
Getting the data
public class GetData extends AsyncTask<String, String, String>{
#Override
protected String doInBackground(String... strings) {
String current = "";
try {
URL url;
HttpURLConnection urlConnection = null;
try {
url = new URL(JSON_URL);
urlConnection = (HttpURLConnection) url.openConnection();
InputStream in = urlConnection.getInputStream();
InputStreamReader isr = new InputStreamReader(in);
int data = isr.read();
while (data != -1) {
current += (char) data;
data = isr.read();
}
return current;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (urlConnection != null) {
urlConnection.disconnect();
}
}
} catch (Exception e){
e.printStackTrace();
}
return current;
}
Displaying the data
#Override
protected void onPostExecute(String s) {
try{
JSONObject jsonObject= new JSONObject(s);
JSONArray jsonArray = jsonObject.getJSONArray("Friends"); //name of array
for(int i = 0; i <jsonArray.length();i++)
{
JSONObject jsonObject1 = jsonArray.getJSONObject(i);
namey=jsonObject.getString("name");
age= jsonObject1.getString("age");
//Hashmap
HashMap<String, String> friends = new HashMap<>();
friends.put("name",namey);
friends.put("age", age);
friendsList.add(friends);
}
} catch (JSONException e) {
e.printStackTrace();
}
//Displaying the results
ListAdapter adapter = new SimpleAdapter(
MainActivity.this,
friendsList,
R.layout.row_layout,
new String[]{"name","age"},
new int[]{R.id.textView, R.id.textView2});
lv.setAdapter(adapter);
}
}
}
It doesnt display anything and i believe it has something to do with the url, but i am not quite sure so please help and thank you in advance
Your mocky JSON from https://run.mocky.io/v3/aff3f637-d04f-45c0-b002-09be1a143784 is wrong format, you need to remove the last character
I would like to show users a list of bar near by them, without map. I have tried by PlaceLikelihoods, it works fine but I can not put any restriction on the types of place found and it shows a map.
So I searched by URL, but the Try / Catch always leads to the exception, the toast found there shows the good result but the list of recyclerview is not filled.
I found a similar problem that said to move the notifyDataSetChanged(), I have done it.
I find APIs and parsing very complicated to master so it's probably a stupid mistake but it's been 2 weeks and I have not yet succeeded.
Thanks for reading.
public class TestMap extends AppCompatActivity {
// CONNECTION_TIMEOUT and READ_TIMEOUT are in milliseconds
public static final int CONNECTION_TIMEOUT = 10000;
public static final int READ_TIMEOUT = 15000;
private LocListAdapter mAdapter;
private EmptyStateRecyclerView mLocRecView;
private ArrayList<LocListUser> data;
private double longitudeUser;
private double latitudeUser;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_loc);
data = new ArrayList<>();
mAdapter = new LocListAdapter(data, TestMap.this);
mLocRecView = findViewById(R.id.locRecView);
mLocRecView.setItemAnimator(new DefaultItemAnimator());
mLocRecView.setLayoutManager(new LinearLayoutManager(TestMap.this));
mLocRecView.setHasFixedSize(true);
//data.clear();
mLocRecView.setAdapter(mAdapter);
mLocRecView.clearStateDisplays();
longitudeUser = getIntent().getDoubleExtra("long", 151.2106085);
latitudeUser = getIntent().getDoubleExtra("lat", -33.8523341);
new AsyncFetch().execute();
}
private class AsyncFetch extends AsyncTask<String, String, String> {
ProgressDialog pdLoading = new ProgressDialog(TestMap.this);
HttpURLConnection conn;
URL url = null;
#Override
protected void onPreExecute() {
super.onPreExecute();
pdLoading.setMessage("\tLoading...");
pdLoading.setCancelable(false);
pdLoading.show();
}
#Override
protected String doInBackground(String... params) {
try {
StringBuilder sb;
sb = new StringBuilder("https://maps.googleapis.com/maps/api/place/nearbysearch/json?");
sb.append("location=").append(latitudeUser).append(",").append(longitudeUser);
sb.append("&radius=5000");
sb.append("&types=" + "bar");
sb.append("&key=API_KEY");
url = new URL(String.valueOf(sb));
} catch (MalformedURLException e) {
e.printStackTrace();
return e.toString();
}
try {
conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(READ_TIMEOUT);
conn.setConnectTimeout(CONNECTION_TIMEOUT);
conn.setRequestMethod("GET");
conn.setDoOutput(true);
} catch (IOException e1) {
e1.printStackTrace();
return e1.toString();
}
try {
int response_code = conn.getResponseCode();
if (response_code == HttpURLConnection.HTTP_OK) {
InputStream input = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8));
StringBuilder result = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
result.append(line);
}
// Pass data to onPostExecute method
return (result.toString());
} else {
return ("unsuccessful");
}
} catch (IOException e) {
e.printStackTrace();
return e.toString();
} finally {
conn.disconnect();
}
}
#Override
protected void onPostExecute(String result) {
pdLoading.dismiss();
try {
JSONArray jArray = new JSONArray(result);
for (int i = 0; i < jArray.length(); i++) {
JSONObject json_data = jArray.getJSONObject(i);
LocListUser locList = new LocListUser();
locList.setAddress(json_data.getString("vicinity"));
locList.setId(json_data.getString("reference"));
locList.setName(json_data.getString("place_name"));
locList.setLat(json_data.getJSONObject("geometry").getJSONObject("location").getString("lat"));
locList.setLon(json_data.getJSONObject("geometry").getJSONObject("location").getString("lng"));
locList.setType(json_data.getString("types"));
locList.setLatUser(latitudeUser);
locList.setLonUser(longitudeUser);
data.add(locList);
mAdapter.notifyDataSetChanged();
}
//mAdapter.notifyDataSetChanged();
mLocRecView.invokeState(EmptyStateRecyclerView.STATE_OK);
} catch (JSONException e) { //e.toString()
e.printStackTrace();
}
}
}
}
you are using hardcoded string
JSONArray jArray = new JSONArray("results");
you have to use
JSONArray jArray = new JSONArray(result);
I was developing a simple application that exctracts some fields of a JSon that tells me in real time what weather is in that exact moment, and I have exctracted only one filed, and I was asking myself: Is it possible to extract more than on field at time?
Here is the the link from where i parse the Json:
https://fcc-weather-api.glitch.me/api/current?lat=35&lon=139
And here's my code:
public class MainActivity extends AppCompatActivity {
Button btnHit;
TextView txtJson;
ProgressDialog pd;
ArrayMap<Integer, String> arrayMap = new ArrayMap<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnHit = (Button) findViewById(R.id.btnHit);
txtJson = (TextView) findViewById(R.id.tvJsonItem);
btnHit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
new JsonTask().execute("https://fcc-weather-api.glitch.me/api/current?lat=35&lon=139");
}
});
}
public class JsonTask extends AsyncTask<String, String, String> {
protected void onPreExecute() {
super.onPreExecute();
pd = new ProgressDialog(MainActivity.this);
pd.setMessage("Please wait");
pd.setCancelable(false);
pd.show();
}
protected String doInBackground(String... params) {
HttpURLConnection connection = null;
BufferedReader reader = null;
try {
URL url = new URL(params[0]);
connection = (HttpURLConnection) url.openConnection();
connection.connect();
InputStream stream = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(stream));
StringBuffer buffer = new StringBuffer();
String line = "";
while ((line = reader.readLine()) != null) {
buffer.append(line + "\n");
Log.d("Response: ", "> " + line);
}
return buffer.toString();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (connection != null) {
connection.disconnect();
}
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
#Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
if (pd.isShowing()) {
pd.dismiss();
}
try {
JSONObject Object = new JSONObject(result);
JSONArray arr = new JSONArray(Object.getString("weather"));
for (int i = 0; i < arr.length(); i++) {
JSONObject jsonPart = arr.getJSONObject(i);
//txtJson.append("main: " + jsonPart.getString("main") + '\n');
arrayMap.put(i, jsonPart.getString("main"));
txtJson.append("main: " + arrayMap.get(i) + '\n');
}
} catch (JSONException e) {
e.printStackTrace();
//txtJson.setText(result);
}
//txtJson.setText(result);
}
}
}
If I understand correctly you want to extract other object alongwith main from the array weather
"weather": [
{
"id": 701,
"main": "Mist",
"description": "mist",
"icon": "https://cdn.glitch.com/6e8889e5-7a72-48f0-a061-863548450de5%2F50n.png?1499366021876"
}
If that is the requirement then you can use the same process like you have done just change the name of the object.
arrayMap.put(i, jsonPart.getString("description"));
or
you can use gson and convert the object in pojo class in one go. Then use the object of the pojo and access the data.
Hope it helps.
I am able to register json data to my server, I am even getting response, but not able to show it in toast as well as send it to other activity (main activity).
I converted the response to string and tried to send to my mainactivity using getter but I am not able to see it in Log.i, even in toast that I mentioned. Here's my code:
class SendJsonDataToServer extends AsyncTask<String, String, String> {
String j;
#Override
protected String doInBackground(String... params) {
String JsonResponse = "";
String JsonDATA = params[0];
HttpURLConnection urlConnection = null;
BufferedReader reader = null;
try {
URL url = new URL("http://gstedge.com/test/invoice/api.php?param=signup");
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoOutput(true);
// is output buffer writter
urlConnection.setRequestMethod("POST");
urlConnection.setRequestProperty("Content-Type", "application/json");
urlConnection.setRequestProperty("Accept", "application/json");
//set headers and method
Writer writer = new BufferedWriter(new OutputStreamWriter(urlConnection.getOutputStream(), "UTF-8"));
writer.write(JsonDATA);
// json data
writer.close();
InputStream inputStream = urlConnection.getInputStream();
//input stream
StringBuffer buffer = new StringBuffer();
if (inputStream == null) {
// Nothing to do.
return null;
}
reader = new BufferedReader(new InputStreamReader(inputStream));
String inputLine;
while ((inputLine = reader.readLine()) != null)
buffer.append(inputLine + "\n");
if (buffer.length() == 0) {
// Stream was empty. No point in parsing.
return null;
}
JsonResponse = buffer.toString();
j= JsonResponse;
//response data
Log.i("o/p:", JsonResponse);
//send to post execute
}
catch (IOException e) {
e.printStackTrace();
} finally {
if (urlConnection != null) {
urlConnection.disconnect();
}
if (reader != null) {
try {
reader.close();
} catch (final IOException e) {
Log.e("wtf", "Error closing stream", e);
}
}
}
return JsonResponse;
}
I was not able to get response in onpostexecute as well so I removed it and thought to convert it in string and send it using getter and parse it in other activity. I am able to see response in log.i("o/p") mentioned above in the code, but I don't know why its not getting sent.
Here's my mainactivity code:
public class MainActivity extends AppCompatActivity {
EditText emailview, numberview, pwview;
Button registerview;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
emailview = (EditText) findViewById(R.id.et1);
numberview = (EditText) findViewById(R.id.et2);
pwview = (EditText) findViewById(R.id.et3);
registerview = (Button) findViewById(R.id.btn1);
}
public void hit(View v) {
String email = emailview.getText().toString();
String contact = numberview.getText().toString();
String pw = pwview.getText().toString();
JSONObject a = new JSONObject();
try {
a.put("mail", email);
a.put("num", contact);
a.put("pass", pw);
} catch (JSONException e) {
e.printStackTrace();
}
if (a.length() > 0) {
new SendJsonDataToServer().execute(String.valueOf(a));
}
SendJsonDataToServer S = new SendJsonDataToServer();
String Jr = S.getJR();
Log.i("out:",Jr);
Toast.makeText(MainActivity.this, Jr, Toast.LENGTH_LONG).show();
Intent i= new Intent(MainActivity.this,UserAreaActivity.class);
startActivity(i);
}
}
The toast I see is empty.
Explanation:
Because you are creating two different objects of SendJsonDataToServer
First:
new SendJsonDataToServer().execute(String.valueOf(a));
Second:
SendJsonDataToServer S = new SendJsonDataToServer();
So these two objects will get different memory allocation. when you get response by this code
String Jr = S.getJR();
then you will get the response that was created in different object from the object you got response. So Jr will be obviously empty. That's why you cannot print the response that you expect.
Solution:
First:
You need to execute
Toast.makeText(MainActivity.this, Jr, Toast.LENGTH_LONG).show();
in
#Override
protected void onPostExecute(String result) {
Toast.makeText(MainActivity.this, result, Toast.LENGTH_LONG).show();
}
method in your AsyncTask like this.
Second:
If you want to send this result to your second activity then you should write code like this in your onPostExecute method.
#Override
protected void onPostExecute(String result) {
Toast.makeText(MainActivity.this, result, Toast.LENGTH_LONG).show();
Intent i = new Intent(MainActivity.this, UserAreaActivity.class);
i.putExtra("result", result);
startActivity(i);
}
and write this code in onCreate() method of UserAreaActivity
Bundle bundle = getIntent().getExtras();
String result = bundle.getString("result");
Toast.makeText(UserAreaActivity.this, result, Toast.LENGTH_LONG).show();
Now you will be able to use result in this activity.
I had a problem here.
I have a login_activity that execute asynctask to get some result from a php file which it connects to mysql database.
public class login_main extends AppCompatActivity implements OnDataSendToActivity{
ViewPager viewPager;
CustomAdapter adapter;
ArrayList<String> image = new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//setSupportActionBar(toolbar);
String type = "getProfileImages";
RetrieveData retrieveData = new RetrieveData(this);
retrieveData.execute(type);
//After Asycntask, get the result and put back into image array
viewPager = (ViewPager) findViewById(R.id.view_pager);
adapter = new CustomAdapter(login_main.this,image);
viewPager.setAdapter(adapter);
}
public void sendData(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
JSONArray result = jsonObject.getJSONArray("result");
for (int i = 0 ; i < result.length(); i++) {
JSONObject obj = result.getJSONObject(i);
String id = obj.getString("image"+i);
image.add("http://192.168.12.252/"+id+"/profile.png");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
When i get the result i try to process the result by using interface from the asynctask
protected void onPostExecute(String result) {
super.onPostExecute(result);
dataSendToActivity.sendData(result);
}
Everything is working fine except that the image array always empty when i pass it to the PageAdapter. How can i pass the data back to activity from asycntask and push into the array image, by using interface, it cant work.
Or anyway i can directly process it in Asyntask and update the ViewPager.
Here is my Asynctask
public class RetrieveData extends AsyncTask<String,Void,String>{
Context context;
RetrieveData(Context ctx) {
context = ctx;
}
private OnDataSendToActivity dataSendToActivity;
public RetrieveData(Activity activity){
dataSendToActivity = (OnDataSendToActivity)activity;
}
#Override
protected String doInBackground(String... params) {
String profile_url = "http://192.168.12.252/getprofile.php";
String image_url = "http://192.168.12.252/imagelist.php";
String type = params[0];
if(type.equals("getProfile")){
try {
String user_name = params[1];
URL url = new URL(profile_url);
HttpURLConnection httpURLConnection = null;
httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
OutputStream outputStream = httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
String post_data = URLEncoder.encode("user_name", "UTF-8")+"="+URLEncoder.encode(user_name, "UTF-8");
bufferedWriter.write(post_data);
bufferedWriter.flush();
bufferedWriter.close();
outputStream.close();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream,"iso-8859-1"));
String result = null;
result = bufferedReader.readLine();
bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();
return result;
} catch (IOException e) {
e.printStackTrace();
}
}else if(type.equals("getProfileImages")){
try {
URL url = new URL(image_url);
HttpURLConnection httpURLConnection = null;
httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
OutputStream outputStream = httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
String post_data = URLEncoder.encode("Image", "UTF-8")+"="+URLEncoder.encode("Image", "UTF-8");
bufferedWriter.write(post_data);
bufferedWriter.flush();
bufferedWriter.close();
outputStream.close();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream,"iso-8859-1"));
String result = null;
result = bufferedReader.readLine();
bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();
return result;
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
#Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
dataSendToActivity.sendData(result);
}
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
}
The execution sequence is all messed up. by the time ur adding data to ur image array the,the empty image array has already been passed to the view pager adapter,therfore ur image array is empty.
u continue to do the same thing but instead of setting view pager adapter in onCreate() set the adapter after u call the method sendData();
modify the sendData() method like this.
public void sendData(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
JSONArray result = jsonObject.getJSONArray("result");
for (int i = 0 ; i < result.length(); i++) {
JSONObject obj = result.getJSONObject(i);
String id = obj.getString("image"+i);
image.add("http://192.168.12.252/"+id+"/profile.png");
}
} catch (JSONException e) {
e.printStackTrace();
}
adapter = new CustomAdapter(login_main.this,image);//set ur image array here
viewPager.setAdapter(adapter);
}