のTextViewで表示する必要があります私はscheduleDate
をフェッチする必要があり、StartTime
、Endtime
、Hours
私のSQLデータベースから、日中であると私はAndroid Studioでテキスト形式で表示する必要があります。しかし、私はtextview
にそれらを表示することができません。誰か助けてください。日付と時刻の形式であるPHP/MySQLからのデータを取得し、それはアンドロイドスタジオで
my php code which will fetch the data`
<?php
error_reporting(0);
require "init.php";
$name = $_POST["name"];
$password = $_POST["password"];
//$name = "sdf";
//$password = "sdf";
$sql = "SELECT * FROM `user_info` WHERE `name`='".$name."' AND `password`='".$password."';";
$result = mysqli_query($con, $sql);
$response = array();
while($row = mysqli_fetch_array($result)){
$response = array("id"=>$row[0],"name"=>$row[1],"password"=>$row[2],"email"=>$row[3],"ScheduleDate"=>$row[4],"StartTime"=>$row[5],"Endtime"=>$row[6],"Hours"=>$row[7]);
}
echo json_encode(array("user_data"=>$response));
?>
と私のアンドロイドコード主な活動:
package com.example.myapplication;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
public class MainActivity extends AppCompatActivity {
EditText name, password;
String Name, Password,ScheduleDate,StartTime,Endtime,Hours;
Context ctx=this;
String NAME=null, PASSWORD=null, EMAIL=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = (EditText) findViewById(R.id.main_name);
password = (EditText) findViewById(R.id.main_password);
}
public void main_register(View v){
// startActivity(new Intent(this,Register.class));
}
public void main_login(View v){
Name = name.getText().toString();
Password = password.getText().toString();
BackGround b = new BackGround();
b.execute(Name, Password);
}
class BackGround extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... params) {
String name = params[0];
String password = params[1];
String data="";
int tmp;
try {
URL url = new URL("http://localhost/sample/loo/login.php");
String urlParams = "name="+name+"&password="+password;
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setDoOutput(true);
OutputStream os = httpURLConnection.getOutputStream();
os.write(urlParams.getBytes());
os.flush();
os.close();
InputStream is = httpURLConnection.getInputStream();
while((tmp=is.read())!=-1){
data+= (char)tmp;
}
is.close();
httpURLConnection.disconnect();
return data;
} catch (MalformedURLException e) {
e.printStackTrace();
return "Exception: "+e.getMessage();
} catch (IOException e) {
e.printStackTrace();
return "Exception: "+e.getMessage();
}
}
@Override
protected void onPostExecute(String s) {
String err=null;
try {
JSONObject root = new JSONObject(s);
JSONObject user_data = root.getJSONObject("user_data");
NAME = user_data.getString("name");
PASSWORD = user_data.getString("password");
EMAIL = user_data.getString("email");
ScheduleDate = user_data.getString("ScheduleDate");
StartTime = user_data.getString("StartTime");
Endtime = user_data.getString("Endtime");
Hours = user_data.getString("Hours");
} catch (JSONException e) {
e.printStackTrace();
err = "Exception: "+e.getMessage();
}
Intent i = new Intent(ctx, Home.class);
i.putExtra("name", NAME);
i.putExtra("password", PASSWORD);
i.putExtra("email", EMAIL);
i.putExtra("ScheduleDate", ScheduleDate);
i.putExtra("StartTime", StartTime);
i.putExtra("Endtime", Endtime);
i.putExtra("Hours", Hours);
i.putExtra("err", err);
startActivity(i);
}
}
}`
そして、これは私の表示ページactvityです:
package com.example.myapplication;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
public class Home extends AppCompatActivity {
String name, password, email, Err,ScheduleDate,StartTime,Endtime,Hours;
TextView nameTV, emailTV, passwordTV, err,ScheduleDateTV,StartTimeTV,EndtimeTV,HoursTV;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
nameTV = (TextView) findViewById(R.id.home_name);
emailTV = (TextView) findViewById(R.id.home_email);
passwordTV = (TextView) findViewById(R.id.home_password);
ScheduleDateTV = (TextView) findViewById(R.id.ScheduleDate);
StartTimeTV = (TextView) findViewById(R.id.StartTime);
EndtimeTV = (TextView) findViewById(R.id.Endtime);
HoursTV = (TextView) findViewById(R.id.Hours);
err = (TextView) findViewById(R.id.err);
name = getIntent().getStringExtra("name");
password = getIntent().getStringExtra("password");
email = getIntent().getStringExtra("email");
ScheduleDate = getIntent().getStringExtra("ScheduleDate");
StartTime = getIntent().getStringExtra("StartTime");
Endtime = getIntent().getStringExtra("Endtime");
Hours = getIntent().getStringExtra("Hours");
Err = getIntent().getStringExtra("err");
nameTV.setText("Welcome "+name);
passwordTV.setText("Your password is "+password);
emailTV.setText("Your email is "+email);
ScheduleDateTV.setText("your date "+ScheduleDate);
StartTimeTV.setText("starting time "+StartTime);
EndtimeTV.setText("ending time "+Endtime);
HoursTV.setText("total hours "+Hours);
err.setText(Err);
}
}
にscheduleDate、のStartTime、終わりの時のデータを追加しますか? – R2R
あなたのLogCatを共有する –
レストアやボレーを使用して休憩API呼び出しを呼び出すことができ、jsonからpojo形式のデータを呼び出すことでデータを表示することができます –