Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用按钮搜索将搜索查询传递给其他活动_Java_Php_Android - Fatal编程技术网

Java 如何使用按钮搜索将搜索查询传递给其他活动

Java 如何使用按钮搜索将搜索查询传递给其他活动,java,php,android,Java,Php,Android,我正在开发一个android求职应用程序,这里是PHP作为后端。从服务器获取工作列表并显示为卡片视图工作正常。在这里,我希望搜索位置和工作标题。那么,如何将我的位置和职务从搜索活动传递到工作活动 private void searchjob() { final String title = jobtitle.getText().toString().trim(); final String location = city.getSelectedItem().t

我正在开发一个android求职应用程序,这里是PHP作为后端。从服务器获取工作列表并显示为卡片视图工作正常。在这里,我希望搜索位置和工作标题。那么,如何将我的位置和职务从搜索活动传递到工作活动

 private void searchjob() {

        final String title = jobtitle.getText().toString().trim();
        final String location = city.getSelectedItem().toString().trim();

        Intent intent = new Intent(HomeActivity.this, MainActivity.class);
        intent.putExtra(title,1);
        intent.putExtra(location,2);


        startActivity(intent);
        overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
    }
这是我的下载卡java类

public class DownloaderCard extends AsyncTask<Void, Integer, String> {
    Context c;
    String address;
    SwipeDeck swipeDeck;
    ProgressDialog pd;
    String url = "";

    public DownloaderCard(Context c, String address, SwipeDeck swipeDeck) {
        this.c = c;
        this.address = address;
        this.swipeDeck = swipeDeck;
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pd = new ProgressDialog(c);
        pd.setTitle("Please Wait");
        pd.setMessage("Loading....");
        pd.show();
    }
    @Override
    protected String doInBackground(Void... params) {
        String data = downloadData();
        return data;
    }
    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        pd.dismiss();
        if(s!=null){
            //Toast.makeText(c, s, Toast.LENGTH_LONG).show();
            ParserCard p = new ParserCard(c, s, swipeDeck);
            p.execute();
        }else {
            Toast.makeText(c, "Unable to download data from downloader", Toast.LENGTH_LONG).show();
        }
    }
    private String downloadData(){
        InputStream is = null;
        String line = null;
        try {
            URL url = new URL(address);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            is = new BufferedInputStream(connection.getInputStream());
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            StringBuffer sb = new StringBuffer();
            if(br != null){
                while ((line = br.readLine()) != null){
                    sb.append(line+"\n");
                }

            }else {
                return null;
            }
            return sb.toString();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(is != null){
                try {
                    is.close();
                }catch (IOException e){
                    e.printStackTrace();
                }
            }
        }
        return null;
    }
}

下面是我用来向PHP服务器发送登录信息的方法。。更新它,使其符合您的目的

      public String LoginOnService(String url,String email,String pass){
                InputStream inputStream = null;
                String result = "";
                try {

                    // 1. create HttpClient
                    HttpClient httpclient = new DefaultHttpClient();

                    // 2. make POST request to the given URL
                    HttpPost httpPost = new HttpPost(url+"?email="+email+"&password="+pass);
                    // 3. Execute POST request to the given URL
                    HttpResponse httpResponse = httpclient.execute(httpPost);
                    if(httpResponse != null){
                       result = EntityUtils.toString(httpResponse.getEntity());
                    }else{
                       result = "Did not work!";
                    }
               } catch (Exception e) {
                    Log.d("InputStream", e.getLocalizedMessage());
               }

               // 11. return result
               return result;
       } 
正如您所看到的,我正在传递一个
字符串
,但是如果您希望以
JSON
的形式发送数据,您可能也会从这些注释中受益。但是在步骤2中,只传递一个url
HttpPost-HttpPost=newhttppost(url)


下面是我用来向PHP服务器发送登录信息的方法。。更新它,使其符合您的目的

      public String LoginOnService(String url,String email,String pass){
                InputStream inputStream = null;
                String result = "";
                try {

                    // 1. create HttpClient
                    HttpClient httpclient = new DefaultHttpClient();

                    // 2. make POST request to the given URL
                    HttpPost httpPost = new HttpPost(url+"?email="+email+"&password="+pass);
                    // 3. Execute POST request to the given URL
                    HttpResponse httpResponse = httpclient.execute(httpPost);
                    if(httpResponse != null){
                       result = EntityUtils.toString(httpResponse.getEntity());
                    }else{
                       result = "Did not work!";
                    }
               } catch (Exception e) {
                    Log.d("InputStream", e.getLocalizedMessage());
               }

               // 11. return result
               return result;
       } 
正如您所看到的,我正在传递一个
字符串
,但是如果您希望以
JSON
的形式发送数据,您可能也会从这些注释中受益。但是在步骤2中,只传递一个url
HttpPost-HttpPost=newhttppost(url)

您应该使用截击来调用Http请求,这将使您的工作更加轻松, 以下是一个例子:-

    final String url = "https://www.joblist.php?title=MyJobTitle&location=London";

// prepare the Request
JsonObjectRequest getRequest = new JsonObjectRequest(Request.Method.GET, url, null,
    new Response.Listener<JSONObject>() 
    {
        @Override
        public void onResponse(JSONObject response) {   
                        // display response     
            Log.d("Response", response.toString());
        }
    }, 
    new Response.ErrorListener() 
    {
         @Override
         public void onErrorResponse(VolleyError error) {            
            Log.d("Error.Response", response);
       }
    }
);

// add it to the RequestQueue   
queue.add(getRequest);
最终字符串url=”https://www.joblist.php?title=MyJobTitle&location=London";
//准备请求
JsonObjectRequest getRequest=新的JsonObjectRequest(Request.Method.GET,url,null,
新的Response.Listener()
{
@凌驾
public void onResponse(JSONObject response){
//显示响应
Log.d(“Response”,Response.toString());
}
}, 
新的Response.ErrorListener()
{
@凌驾
公共无效onErrorResponse(截击错误){
Log.d(“错误.响应”,响应);
}
}
);
//将其添加到RequestQueue
添加(getRequest);
您应该使用截击来调用Http请求,这将使您的工作更加轻松, 以下是一个例子:-

    final String url = "https://www.joblist.php?title=MyJobTitle&location=London";

// prepare the Request
JsonObjectRequest getRequest = new JsonObjectRequest(Request.Method.GET, url, null,
    new Response.Listener<JSONObject>() 
    {
        @Override
        public void onResponse(JSONObject response) {   
                        // display response     
            Log.d("Response", response.toString());
        }
    }, 
    new Response.ErrorListener() 
    {
         @Override
         public void onErrorResponse(VolleyError error) {            
            Log.d("Error.Response", response);
       }
    }
);

// add it to the RequestQueue   
queue.add(getRequest);
最终字符串url=”https://www.joblist.php?title=MyJobTitle&location=London";
//准备请求
JsonObjectRequest getRequest=新的JsonObjectRequest(Request.Method.GET,url,null,
新的Response.Listener()
{
@凌驾
public void onResponse(JSONObject response){
//显示响应
Log.d(“Response”,Response.toString());
}
}, 
新的Response.ErrorListener()
{
@凌驾
公共无效onErrorResponse(截击错误){
Log.d(“错误.响应”,响应);
}
}
);
//将其添加到RequestQueue
添加(getRequest);
在职活动

 String myvalue= getIntent().getExtras("job_title");
 String myvalue2= getIntent().getExtras("city");
php代码

最终字符串url=“+myvalue+”&location=“+myvalue2

在职活动

 String myvalue= getIntent().getExtras("job_title");
 String myvalue2= getIntent().getExtras("city");
php代码


最终字符串url=“+myvalue+”&location=“+myvalue2

您询问如何在两个活动之间传递数据,但您已经在这里传递了数据
intent.putExtra(title,1)你现在想做什么?是的。但是如何传递php代码您询问了如何在两个活动之间传递数据,但是您已经在这里传递了数据
intent.putExtra(title,1)你现在想做什么?是的。但是如何传递它php代码我试过了,但它是无效的。不工作。请告诉我如何传递搜索查询以传递URL我在这里变得更困惑了,那么您所说的搜索查询是什么意思?您是指在
PHP服务器上执行搜索的查询吗?在我的主页活动中检查此链接,有2个编辑文本、位置和职务标题以及一个按钮,我想将标题和位置值传递到职务活动url中。。是我的url,那么我如何将值传递到php url尝试在您的浏览器中,我将使用您提供的url传递location和title的值,
alot.ae/api/joblist.php?location=London&title=programmer
如果您在php中正确处理它,则应返回搜索结果。是的。它工作,但是。我不知道该如何通过考试,安德烈我试过了,但它很难通过。不工作。请告诉我如何传递搜索查询以传递URL我在这里变得更困惑了,那么您所说的搜索查询是什么意思?您是指在
PHP服务器上执行搜索的查询吗?在我的主页活动中检查此链接,有2个编辑文本、位置和职务标题以及一个按钮,我想将标题和位置值传递到职务活动url中。。是我的url,那么我如何将值传递到php url尝试在您的浏览器中,我将使用您提供的url传递location和title的值,
alot.ae/api/joblist.php?location=London&title=programmer
如果您在php中正确处理它,则应返回搜索结果。是的。它工作,但是。我不知道如何通过它