Subjetfile.getSubjectIDの値をListViewからSubjectActivityの別のアクティビティに渡すと、$ id = $ _ GET ['subjectID'];私のPHPコードでnullにはなりません?誰でも助けることができますか?私はlistViewの中に置くサブジェクトのリストを持っています、listViewのアイテムをクリックするとSubjectActivityに渡したいのですが、アクティビティはサブジェクトの詳細を表示しますが、PHPコードは$のために機能していないようですid。誰かが私が感謝することを助けることができれば、ありがとう!1つのアクティビティから別のアクティビティに値を渡すには
public class SubjectActivity extends AppCompatActivity {
private ImageView imageViewDefault;
private TextView textViewDefaultName;
private TextView textViewDefaultDescription1;
private TextView textViewDefaultDescription2;
private static final String GET_URL_SUBJECT = "https://arlearn.000webhostapp.com/getSubject.php";
private static final int TAG1 = 1;
private ProgressDialog pDialog;
private subjectFile subjectfile;
private String result = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_subject);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
imageViewDefault = (ImageView)findViewById(R.id.imageViewSubject);
textViewDefaultName = (TextView)findViewById(R.id.textViewName);
textViewDefaultDescription1 = (TextView)findViewById(R.id.textViewContent1);
textViewDefaultDescription2 = (TextView)findViewById(R.id.textViewContent2);
pDialog = new ProgressDialog(this);
}
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.subject, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item)
{
int id = item.getItemId();
if(id == R.id.action_refresh) {
getSubjectContent(getApplicationContext(), GET_URL_SUBJECT);
}
return super.onOptionsItemSelected(item);
}
private void getSubjectContent(Context context, String url) {
RequestQueue request = Volley.newRequestQueue(context);
if (!pDialog.isShowing())
pDialog.setMessage("Syn with server...");
pDialog.show();
JsonArrayRequest requestsubject = new JsonArrayRequest(url,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
try {
for (int i = 0; i < response.length(); i++) {
JSONObject subjectResponse = (JSONObject) response.get(i);
String name = subjectResponse.getString("name");
String image = subjectResponse.getString("image");
String description1 = subjectResponse.getString("Description1");
String description2 = subjectResponse.getString("Description2");
subjectfile = new subjectFile(name, image, description1, description2);
}
loadFile();
if (pDialog.isShowing())
pDialog.dismiss();
}catch(Exception e)
{
Toast.makeText(getApplicationContext(), "Error:" + e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.i("tagconvertstr", "["+result+"]");
Toast.makeText(getApplicationContext(), "Error" + error.getMessage(), Toast.LENGTH_LONG).show();
error.printStackTrace();
if (pDialog.isShowing())
pDialog.dismiss();
}
}
);
request.add(requestsubject);
}
private void loadFile() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] imageBytes = baos.toByteArray();
imageBytes = Base64.decode(subjectfile.getImage(), Base64.DEFAULT);
Bitmap decodeImage = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
imageViewDefault.setImageBitmap(decodeImage);
textViewDefaultName.setText(subjectfile.getName());
textViewDefaultDescription1.setText(subjectfile.getDescription1());
textViewDefaultDescription2.setText(subjectfile.getDescription2());
}
}
<?php
\t include("connection1.php");
\t // connecting to db
\t $conn = mysqli_connect($hostname_localhost, $username_localhost, $password_localhost, $database_localhost);
\t /* check connection */
\t if (mysqli_connect_errno()) {
\t \t echo "Error: Connect failed: %s\n";
\t \t exit();
\t }
\t $response = array();
\t
\t $id=$_GET['subjectID'];
\t
\t $query = "SELECT image, name, Description1, Description2 from subject WHERE subjectID = ".$id;
\t
\t
\t /* Select queries return a resultset */
\t if ($result = mysqli_query($conn, $query))
\t {
\t $response = array();
\t
\t while ($row = mysqli_fetch_array($result))
\t {
\t $item = array();
\t $item["image"] = base64_encode($row["image"]);
\t \t $item["name"] = $row["name"];
\t \t $item["Description1"] = $row["Description1"];
\t \t $item["Description2"] = $row["Description2"];
\t \t array_push($response, $item);
\t }
\t mysqli_free_result($result);
\t }
\t else{
\t $response["success"] = 0;
$response["message"] = "Required field(s) is missing";
\t }
\t
\t echo json_encode($response);
\t /* close connection */
\t mysqli_close($conn);
?>
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
subjectFile subjectfile = imageAdapter.getItem(position);
Log.i("Database", subjectfile.getSubjectID());
Intent intent = new Intent(getActivity(), SubjectActivity.class);
startActivity(intent);
}
});
可能な重複https://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in -android-application) – BenRoob