私はAndroidにはとても新しいので、ここや他のウェブサイトから多くの投稿に記載されているソリューションを試してみてください。 Androidのアクティビティ(ボタンをクリックしたとき)から2つの変数を渡したいと思います。Androidからphpに変数を送信するだけです
私が試みているのは、アクティビティからPHPページに変数を渡すことです。 これはシミュレータ上で動作しますか?または、私はそれが動作確認するためにアプリをリリースする必要がありますか? "onclickの"
しかし、と
public class Main3Activity extends AppCompatActivity {
public String num_pal, precio, l_origen, l_destino, texto, banner_id, full_id;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
Intent intent=getIntent();
double precio = intent.getExtras().getDouble("precio");
String l_origen = intent.getExtras().getString("l_origen");
String l_destino = intent.getExtras().getString("l_destino");
String texto= intent.getExtras().getString("texto");
int pal = intent.getExtras().getInt("num_pal");
num_pal = String.valueOf(pal);
String precio_rounded = String.format("%.2f", precio);
TextView txtCambio = (TextView) findViewById(R.id.textView4);
txtCambio.setText("Precio Total: "+ precio_rounded + " €");
}
void MakePostRequest() {
String posting_url ="https://www.example.org/movil/ingles/page.php";
StringRequest postRequest = new StringRequest(Request.Method.POST, posting_url ,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
precio= jsonResponse.getString("precio_rounded");
l_origen= jsonResponse.getString("l_origen");
l_destino= jsonResponse.getString("l_destino");
texto= jsonResponse.getString("texto");
num_pal= jsonResponse.getString("num_pal");
} catch (JSONException e) {
e.printStackTrace();
banner_id = null;
full_id = null;
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
precio= null;
l_origen= null;
l_destino= null;
texto= null;
}
}
) {
// here is params will add to your url using post method
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<>();
params.put("precio", precio);
params.put("l_origen", l_origen);
params.put("l_destino", l_destino);
params.put("texto", texto);
params.put("num_pal", num_pal);
//params.put("2ndParamName","valueoF2ndParam");
return params;
}
};
Volley.newRequestQueue(this).add(postRequest);
}
そしてボタン:
は、私は、次のコード(Sohail Zahidのおかげで)持って、今
ではお時間をいただき、ありがとうございますこのボタンをクリックするとアプリケーションが終了し、エラーが報告されます。
誰にも理由がありますか?
また、私は画面でそれらを示すよりも、これらの変数で何かを行うことができないことを読んで、私は彼らと「再生」したい場合は、私がする必要がありますそれらをデータベースに格納する。本当?それはどういう意味ですか? – Whencesoever
例えば、それらの変数を他のPHPページに再送したいのであれば、それらをデータベースに保存する必要がありますか?あなたの答えをありがとう – alberzyzz
それは本当ではないです。 Androidから最初のPHPスクリプトに変数を送信するとしましょう。それを操作する。操作された変数は、別のPHPに送信されます。あなたはそれが同じ目的ではないことを知る必要があります。あなたは値を渡すことができます。名前による変数ではありません。 – Whencesoever