如何在android布局的listview中显示mysql数据库的单行数据?
我尝试在配置文件布局中显示员工详细信息,我尝试使用如何在android布局的listview中显示mysql数据库的单行数据?,android,Android,我尝试在配置文件布局中显示员工详细信息,我尝试使用列表视图显示员工详细信息,我还尝试了表格布局,但我只能水平显示,但我希望他们在垂直布局中逐个显示。我不知道如何以垂直顺序显示它们,是否有可能以垂直顺序显示它们, 这是我的代码: profile layout package com.example.myapplication; import android.os.AsyncTask; import android.support.v7.app.AppCompatActivity; imp
列表视图显示员工详细信息,我还尝试了表格布局,但我只能水平显示,但我希望他们在垂直布局中逐个显示。我不知道如何以垂直顺序显示它们,是否有可能以垂直顺序显示它们,
这是我的代码:
profile layout
package com.example.myapplication;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class Profile extends AppCompatActivity {
ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
listView = (ListView) findViewById(R.id.listView);
getJSON(Config_URLS.TAG_PROFILE);
}
private void getJSON(final String urlWebService) {
class GetJSON extends AsyncTask<Void, Void, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show();
try {
loadIntoListView(s);
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
protected String doInBackground(Void... voids) {
try {
URL url = new URL(urlWebService);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
StringBuilder sb = new StringBuilder();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
String json;
while ((json = bufferedReader.readLine()) != null) {
sb.append(json + "\n");
}
return sb.toString().trim();
} catch (Exception e) {
return null;
}
}
}
GetJSON getJSON = new GetJSON();
getJSON.execute();
}
private void loadIntoListView(String json) throws JSONException {
JSONArray jsonArray = new JSONArray(json);
String[] profiledata = new String[jsonArray.length()];
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject obj = jsonArray.getJSONObject(i);
profiledata[i] = obj.getString("Profile_Data");
}
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, profiledata);
listView.setAdapter(arrayAdapter);
}
}
这是我的json输出:
{"Profile_Data":[{"StoreID":"22325","EmployeeId":"15","Cashier_name":"","Cashier_id":"0","Payroll_clockin":"","Employee_First_Name":"Damiana","Employee_Middle_Name":"","Employee_Last_Name":"Lobato","Color":null,"Sex":"male","Address":"1st","Email":"damiana_ala@hh.com","Cell":"2179356","City":"Sacramento","State":"CA","Pincode":"9999","Role":"Shiftlead","Status":"N","Basicpay":"0.00","Username":"rajesh","Password":"1995","Dateofhire":"0000-00-00","DateofTerm":null}]}
请任何人帮我找到这样的解决方案输出
StoreID: 22325
EmployeeId: 15
.
.
.
Listview从不放在scrollview中
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#3d455b"
tools:context=".Profile">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="271dp"
android:layout_weight="1"
android:orientation="vertical"
android:paddingTop="40dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:text="MY PROFILE"
android:textColor="@android:color/white"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
您必须创建自定义适配器以查看listview中的项 它不工作bro,我想一个接一个地以垂直顺序显示它们是否有任何可能的解决方案?不使用/使用listviewsplit json对象到单个变量中,然后通过“\n”(断开字符串)附加到单个字符串中并放入适配器。bro您能为它发布任何示例代码吗,以便我能理解。
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#3d455b"
tools:context=".Profile">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="271dp"
android:layout_weight="1"
android:orientation="vertical"
android:paddingTop="40dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:text="MY PROFILE"
android:textColor="@android:color/white"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>