-2

Hello I am creating an android app where i want to know how to send http request using textView elements .

I have created a for whose summery has been displayed in another activity on textView which is non editable.

I have edited the following code and added the http request code which is ok now and now i want to known that i have to add the parameter such as the name, type and action i have gone through some examples but its getting me confused i am not getting it how actually i am apply those codes here

added http request code are as follows

public void sendData(){
        nameText =(TextView)findViewById(R.id.content);
        viewDateText =(TextView)findViewById(R.id.showDate);
        viewEmailText=(TextView)findViewById(R.id.showEmail);
        viewMobileText=(TextView)findViewById(R.id.showMobileNumber);
        viewTotalAdultText = (TextView)findViewById(R.id.showTotalAdults);
        ViewTotalChildren =(TextView)findViewById(R.id.showTotalChildrens);
        viewChildAge =(TextView)findViewById(R.id.showChildrensAge);
        viewTotalRoomsText =(TextView)findViewById(R.id.showTotalRooms);
        viewDepartureText =(TextView)findViewById(R.id.showDepartureCity);
        viewDeatinationText =(TextView)findViewById(R.id.showDestination);
        viewDaysText =(TextView)findViewById(R.id.showTotalDays);
        viewBudgetText =(TextView)findViewById(R.id.showBudget);
        viewPreferHotelText =(TextView)findViewById(R.id.showHotelPreferance);
        viewAirticketText =(TextView)findViewById(R.id.showAirticketRequired);
        viewIntercityText = (TextView)findViewById(R.id.showIntercityTravel);
        viewTravelTypeText = (TextView)findViewById(R.id.showTraveType);
        viewMealText =(TextView)findViewById(R.id.showMealPlan);
        viewInfoText = (TextView)findViewById(R.id.showAdditionalInfo);

        nameText.getText().toString();
        viewDateText.getText().toString();
        viewEmailText.getText().toString();
        viewMobileText.getText().toString();
        viewTotalAdultText.getText().toString();
        ViewTotalChildren.getText().toString();
        viewChildAge.getText().toString();
        viewTotalRoomsText.getText().toString();
        viewDepartureText.getText().toString();
        viewDeatinationText.getText().toString();
        viewDaysText.getText().toString();
        viewBudgetText.getText().toString();
        viewPreferHotelText.getText().toString();
        viewAirticketText.getText().toString();
        viewIntercityText.getText().toString();
        viewTravelTypeText.getText().toString();
        viewMealText.getText().toString();
        viewInfoText.getText().toString();

submitData.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                HttpClient httpclient = new DefaultHttpClient();
                HttpPost post = new HttpPost("http://routern.com/EldestinoAction");
                String json = "";

                try{



                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("nameText",nameText);
                    jsonObject.put("date",viewDateText);
                    jsonObject.put("Email",viewEmailText);
                    jsonObject.put("mobile",viewMobileText);
                    jsonObject.put("Totaladult",viewTotalAdultText);
                    jsonObject.put("totalchildren",ViewTotalChildren);
                    jsonObject.put("childrenAge",viewChildAge);
                    jsonObject.put("hotelRooms",viewTotalRoomsText);
                    jsonObject.put("departure",viewDepartureText);
                    jsonObject.put("destination",viewDeatinationText);
                    jsonObject.put("days",viewDaysText);
                    jsonObject.put("budget",viewBudgetText);
                    jsonObject.put("preferhotel",viewPreferHotelText);
                    jsonObject.put("flight",viewAirticketText);
                    jsonObject.put("intercity",viewIntercityText);
                    jsonObject.put("travelType",viewTravelTypeText);
                    jsonObject.put("meal",viewMealText);
                    jsonObject.put("info",viewInfoText);



                    json = jsonObject.toString();
                    StringEntity se = new StringEntity(json);
                    post.setEntity(se);
                    post.setHeader("Accept", "application/json");
                    post.setHeader("Content-type", "application/json");
                    httpclient.execute(post);
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        });

        }

i want to known that i have to add the parameter such as the name, type and action i have gone through some examples but its getting me confused i am not getting it how actually i am apply those codes here

Moulick
  • 45
  • 5
  • And so what you tried or searched for Http request. Did you see [HttpUrlConnection](https://developer.android.com/reference/java/net/HttpURLConnection.html). You have same question here created 18 hours ago : [i-want-to-get-information-about-how-to-read-data-from-textview](http://stackoverflow.com/questions/38252826/i-want-to-get-information-about-how-to-read-data-from-textview). Sorry about but i will give you minus point because you didnt searched anything yet.If you go google and search for **android how to make http request** you will get so many examples. – Yasin Kaçmaz Jul 08 '16 at 13:17
  • i have searched sir without searching i will not b posting here – Moulick Jul 08 '16 at 13:25
  • okey then why you creating same question you can edit your previous question what you tried and which guides you take a look at. I am saying it for you because you getting minus points. – Yasin Kaçmaz Jul 08 '16 at 13:26

1 Answers1

0

Create a model with all these values. Lets say

public class Data {
  private String name;
  private String email;     

  public String getName() {
    return Name;
 }

 public void setName(String name) {
    this.name = name;
 } 
}

Then in Activity create an object and set all values

 Data data = new Data();
    data.name =  nameText.getText().toString();

Use retrofit2 for http service where you can send directly the object as a parameter.retrofit documentation here

Sivakumar
  • 349
  • 2
  • 10
  • how can it be data.name – Moulick Jul 09 '16 at 03:47
  • We have to create a pojo class with all the required fields to send. Here data is a reference of that model class. So we can assign directly like data.name = 'value' – Sivakumar Jul 09 '16 at 04:22
  • i have created a class have use getter and setter method in it but when u will write data. it will show data.getName not data.name – Moulick Jul 09 '16 at 05:48
  • use data.setName(nameText.getText().toString()) – Sivakumar Jul 09 '16 at 05:56
  • set data is working but i want to get the data and on using get data its showing error on doing it will get the data from text view and will send http request – Moulick Jul 09 '16 at 06:03
  • i have edited the code and have added the http request but have to add the request parameters as name,type,action have seen some example but i am getting confused about it . Need help if any one can suggest to make it perfect – Moulick Jul 10 '16 at 13:15
  • helo can any one give suggestions on it – Moulick Jul 14 '16 at 07:42