1. Download our Official Android App: Forums for Android!

Apps sending request to remote php connected to database (search function)

Discussion in 'Android Development' started by jdgower15, Aug 10, 2011.

  1. jdgower15

    jdgower15 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Aug 10, 2011

    Aug 10, 2011
    2
    0
    5
    OK...I am very new to android development. I recently built an intranet for my company and have a need/want to access the information on the intranet through an android application. Mainly, this is a list of clients. I have used another program I found on the internet and modified it to get my list and I can do so using code like this:

    Code (Text):
    1. JSONObject json = JSONfunctions.getJSONfromURL("http://www.websitehere.com/json.php?keyword=patel");
    This successfully gets a list of clients via a mysql lookup and echo's that list as JSON...this all works fine, the problem I am having is defining that 'patel'...

    I would like to add a text box where one would enter 'john' or 'patel' or whatever, click a button and the application searches and returns the results. Please keep in mind I am very new to all of this and I apologize. At this point I'm not even sure how to make my application wait until a button is clicked to run.

    Thanks for any help you may be able to provide. I am very frustrated and would even send my current application (eclipse export) to someone to look at if you're willing.
     

    Advertisement

  2. jdgower15

    jdgower15 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Aug 10, 2011

    Aug 10, 2011
    2
    0
    5
    OK...got it, somehow...

    Basically, I changed the public void onCreate to public void whatever()...then i made a new onCreate which called the search box/button, once the button is clicked it calls to whatever() function to perform the search...whatever() in the below is actually startService()....

    Code (Text):
    1.  
    2. public class test extends ListActivity {
    3.     /** Called when the activity is first created. */
    4.     private EditText input;
    5.     @Override
    6.     public void onCreate(Bundle savedInstanceState) {
    7.         super.onCreate(savedInstanceState);
    8.         setContentView(R.layout.listplaceholder);
    9.        
    10.         Button start = (Button)findViewById(R.id.startButton);
    11.        
    12.         start.setOnClickListener(new OnClickListener() {
    13.             public void onClick(View v){
    14.                 startService();
    15.             }
    16.         });
    17.        
    18.     }
    19.    
    20.     public void startService(){
    21.         ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
    22.         EditText input = (EditText) findViewById(R.id.search_edit_text);
    23.         JSONObject json = JSONfunctions.getJSONfromURL("http://www.website.com/json.php?keyword=" + input.getText().toString() + "");
    24.  
     

Share This Page

Loading...