Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8881797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:25:08+00:00 2026-06-14T20:25:08+00:00

I am using wordpress in my website.In one of my xml file user have

  • 0

I am using wordpress in my website.In one of my xml file user have to fill contents like books price etc then i want to post that data from android App to website when user clicks on post button. How can i do that. It would be very helpful if you provide any information regarding this. following is my code

public class Post_Ads extends Activity {
private static final int SELECT_PHOTO = 100;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_post__ads);

    // do action when click on browse button
    Button button = (Button) findViewById(R.id.browse_btn);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Perform action on click
             Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
             photoPickerIntent.setType("image/*");
             startActivityForResult(photoPickerIntent, SELECT_PHOTO);   

        }
    });
    Button btnpost = (Button) findViewById(R.id.post_btn);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Perform action on click


        }
    });

}
// select photo from phone gallery 
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { 
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent); 

    switch(requestCode) { 
    case SELECT_PHOTO:
        if(resultCode == RESULT_OK){  
            Uri selectedImage = imageReturnedIntent.getData();
            InputStream imageStream;
            try {
                imageStream = getContentResolver().openInputStream(selectedImage);
                 Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    }

}
public void postData(String title, String price, String city, String state, String country,String zip, String description, String image) {

    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("site url");

    try {
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        nameValuePairs.add(new BasicNameValuePair("Title", title));
        nameValuePairs.add(new BasicNameValuePair("price", price));
        nameValuePairs.add(new BasicNameValuePair("City", city));
        nameValuePairs.add(new BasicNameValuePair("State", state));
        nameValuePairs.add(new BasicNameValuePair("Country", country));
        nameValuePairs.add(new BasicNameValuePair("Zip/Postal Code", zip));
        nameValuePairs.add(new BasicNameValuePair("Description", description));
        nameValuePairs.add(new BasicNameValuePair("Image", image));
        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);

    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }

}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_post__ads, menu);
    return true;
}


@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:

            return true;
    }
    return super.onOptionsItemSelected(item);
}

}

activity_post_ads.xml file

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="vertical" >


<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="top|left"
    android:text="@string/PostYourAds" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="" />
  <LinearLayout  android:layout_width="wrap_content"        android:layout_height="fill_parent" >
 <TextView
android:id="@+id/title"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:text="@string/Title" />
  <EditText
 android:id="@+id/title1"
 android:layout_width="210dp"
 android:layout_height="wrap_content"
 android:gravity="left"
 android:hint="@string/none" >
   <requestFocus />
    </EditText>
      </LinearLayout>
   <LinearLayout  android:layout_width="wrap_content" android:layout_height="fill_parent" >
     <TextView
      android:id="@+id/price"
      android:layout_width="67dp"
      android:layout_height="wrap_content"
      android:text="@string/price" />
  <EditText
 android:id="@+id/price1"
 android:layout_width="210dp"
 android:layout_height="wrap_content"
 android:ems="10"
 android:hint="@string/none"
 android:inputType="number" >
     <requestFocus />
 </EditText>
   </LinearLayout>

    <requestFocus />
 </EditText>
 </LinearLayout>

  <LinearLayout  android:layout_width="wrap_content" android:layout_height="fill_parent" >
<TextView
android:id="@+id/state"
android:layout_width="68dp"
android:layout_height="wrap_content"
android:text="@string/state" />

 <EditText
 android:id="@+id/state1"
android:layout_width="210dp"
 android:layout_height="wrap_content"
 android:ems="10"
 android:hint="@string/none" >

   <requestFocus />
  </EditText>
  </LinearLayout>

<LinearLayout  android:layout_width="wrap_content" android:layout_height="fill_parent" >
     <TextView
      android:id="@+id/zip"
      android:layout_width="73dp"
      android:layout_height="match_parent"
      android:text="@string/zip" />
 <EditText
 android:id="@+id/zip1"
 android:layout_width="210dp"
 android:layout_height="wrap_content"
 android:layout_weight="1"
 android:ems="10"
 android:inputType="number"
 android:hint="@string/none">

 <requestFocus />
</EditText>
  </LinearLayout>

<LinearLayout  android:layout_width="wrap_content" android:layout_height="fill_parent"  >
 <TextView
android:id="@+id/description"
android:layout_width="88dp"
android:layout_height="30dp"
android:text="@string/description" />
 <EditText
  android:id="@+id/editText1"
  android:layout_width="210dp"
  android:layout_height="wrap_content"
  android:layout_weight="1"
  android:ems="10"
  android:hint="@string/none"
  android:inputType="textMultiLine" />
    </LinearLayout>

 <LinearLayout  android:layout_width="wrap_content" android:layout_height="fill_parent" >
    <TextView
      android:id="@+id/Image"
      android:layout_width="73dp"
      android:layout_height="33dp"
      android:text="@string/image" />
<EditText
 android:id="@+id/image1"
 android:layout_width="134dp"
 android:layout_height="wrap_content"
 android:ems="10"
 android:hint="@string/none" >

 <requestFocus />
 </EditText>

 <Button
 android:id="@+id/browse_btn"
 style="?android:attr/buttonStyleSmall"
 android:layout_width="71dp"
 android:layout_height="wrap_content"
 android:text="@string/browse_btn" />
 </LinearLayout>

 <Button
  android:id="@+id/post_btn"
  android:layout_width="100dp"
  android:layout_height="wrap_content"
  android:layout_gravity="center_horizontal"
  android:text="@string/post"
  android:onClick="postData()" />

 </LinearLayout>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:25:09+00:00Added an answer on June 14, 2026 at 8:25 pm

    You shold know about HTTP classes first. Example code for posting data to server from your Android app would look like below.

    public void postData(String bookname, String price) {
    
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("your site url");
    
        try {
            // Add your data
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            nameValuePairs.add(new BasicNameValuePair("book", bookname));
            nameValuePairs.add(new BasicNameValuePair("price", price));
            // Execute HTTP Post Request
            HttpResponse response = httpclient.execute(httppost);
    
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
        } catch (IOException e) {
            // TODO Auto-generated catch block
        }
    
    }
    

    So List<NameValuePair> nameValuePairs is going to hold data that should go to server through POST method. Pass your values like below.

    nameValuePairs.add(new BasicNameValuePair("book", bookname));
    nameValuePairs.add(new BasicNameValuePair("price", price));
    

    Basically the above function should be called when a button is clicked like below,

         postbutton.setOnClickListener(new OnClickListener() {  
             public void onClick(View v)
             {
                // call postData here.
             }
         });
    

    Make sure that you have set all the things at your site to process these requests. Note that for some newer or recent android versions you need to have AsyncTask for performing Network operations.

    Edit: Change your oncreate method to code below. You have not called the postData(….) method.Thats why you didn’t get. One more thing, To upload files to a server you need to have different code look here you will get some idea.

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_post__ads);
    
        // do action when click on browse button
        Button button = (Button) findViewById(R.id.browse_btn);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // Perform action on click
                 Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                 photoPickerIntent.setType("image/*");
                 startActivityForResult(photoPickerIntent, SELECT_PHOTO);   
    
            }
        });
        Button btnpost = (Button) findViewById(R.id.post_btn);
        btnpost.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // Perform action on click
                 postData("title","price", "city", "state","country","zip", "description",     "image");     
    
            }
        });
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website, using the latest wordpress version, in one language and hosted
I am using wordpress for my website like a CMS, also have installed ALL
Im using wordpress for my website and i have a massive amount of data
I have a few questions regarding website creation using the Wordpress CMS. With small
My website (using WordPress) has an .htaccess file located in the root area with
I own a website say xyz.com using wordpress. I have to transfer the wordpress
I have created my website using wordpress 3.4.1 and, I tried sharing my webpage
I want to display on my Wordpress website using MapMyFitness's API. It needs to
I am using wordpress as my cms and building a website. I use Graphene
I am planning a new website with codeigniter using wordpress. this site will contain

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.