建议不要使用列表内列表的所有地方,但我必须使用与列表内列表相同的内容。有任何方法可以与列表中的列表相同。我已经看过可扩展列表视图和this,但无法解决我的问题。我的要求看起来像
**ListView**
**TextView**
**TextView**
**ListView**(i have used Linear layout in here)
在我的布局中,我已将线性布局放置在内部 listView 的位置。内部ListView(在我的情况下为线性布局)仅在innerView中设置一个JSON数据我希望在Inner中显示与外部ListView相同的内容。这有可能吗? 的 fragment_fee
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linear_receipt1_fee"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#008b8b"
android:orientation="horizontal">
<TextView
android:id="@+id/student_profile_fee_ReceiptIssuedDate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:gravity="center"
android:padding="6dp"
android:text="Date"
android:textColor="#fff"
android:textStyle="bold" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#FFFFFF" />
<TextView
android:id="@+id/student_profile_fee_ReceiptIssuedNumber"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:gravity="center"
android:padding="6dp"
android:text="Receipt number"
android:textColor="#fff"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="@+id/receipt1_fee"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#A4ACB0"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:padding="5dp"
android:text="Description"
android:textSize="12dp"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:padding="5dp"
android:text="Amount (Nrs) "
android:textSize="12dp"
android:textStyle="bold">
</TextView>
</LinearLayout>
////this is the replacement of ListView in Inner
<LinearLayout
android:id="@+id/student_profile_fee_linearlayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/student_profile_fee_description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left|center"
android:paddingLeft="70dp"
android:paddingTop="10dp"
android:text="Sports"
android:textSize="10dp" />
<TextView
android:id="@+id/student_profile_fee_amount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left|center"
android:paddingLeft="70dp"
android:paddingTop="10dp"
android:text="1000"
android:textSize="10dp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#C5CED1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#DCE2E8"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="70dp"
android:text="Total"
android:textSize="10dp"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="70dp"
android:text="552"
android:textSize="10dp"
android:textStyle="bold" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#C5CED1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#DCE2E8"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="70dp"
android:text="Status"
android:textSize="10dp"
android:textStyle="bold" />
<TextView
android:id="@+id/student_profile_fee_status"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="70dp"
android:text="Paid"
android:textColor="#108B89"
android:textSize="10dp"
android:textStyle="bold" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#C5CED1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#DCE2E8"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="70dp"
android:text="Received Date"
android:textSize="10dp"
android:textStyle="bold" />
<TextView
android:id="@+id/student_profile_fee_FeeReceiptDate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="70dp"
android:text="9 March,2017"
android:textSize="10dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#fff" />
</LinearLayout>
</LinearLayout>
student_fees_listview
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#2E353D"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_gravity="center_horizontal"
android:orientation="horizontal">
<ImageView
android:layout_width="30dp"
android:layout_height="match_parent"
android:padding="3dp"
android:src="@mipmap/fee" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"
android:text="Fees"
android:textColor="#fff"
android:textSize="17dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<ListView
android:id="@+id/list_student_fees"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
CustomFeeListStudentAdapter
public class CustomFeeListStudentAdapter extends BaseAdapter {
LinearLayout receipt1, receipt2, receipt3, receipt4;
LinearLayout receipt1detail, receipt2detail, receipt3detail, receipt4detail;
Context mContext;
ArrayList<StudentFeeInformation> student_list;
String TAG = "HomeTab_adapter";
public CustomFeeListStudentAdapter(Context mContext, ArrayList<StudentFeeInformation> student_list) {
super();
this.mContext = mContext;
this.student_list = student_list;
}
@Override
public int getCount() {
return student_list.size();
}
@Override
public Object getItem(int arg0) {
return arg0;
}
@Override
public long getItemId(int arg0) {
return arg0;
}
@Override
public View getView(final int postion, View convertView, ViewGroup parent) {
final Holder viewHolder;
if (convertView == null) {
// inflate the layout
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.fragment_fee, parent, false);
// well set up the ViewHolder
viewHolder = new Holder();
viewHolder.student_profile_fee_status = (TextView) convertView.findViewById(R.id.student_profile_fee_status);
viewHolder.student_profile_ReceiptIssuedDate = (TextView) convertView.findViewById(R.id.student_profile_fee_ReceiptIssuedDate);
viewHolder.student_profile_ReceiptIssuedNumber = (TextView) convertView.findViewById(R.id.student_profile_fee_ReceiptIssuedNumber);
viewHolder.student_profile_FeeReceivedDate = (TextView) convertView.findViewById(R.id.student_profile_fee_FeeReceiptDate);
viewHolder.student_profile_Fee_Amount = (TextView) convertView.findViewById(R.id.student_profile_fee_amount);
viewHolder.student_profile_Fee_Description = (TextView) convertView.findViewById(R.id.student_profile_fee_description);
} else {
// we've just avoided calling findViewById() on resource everytime
// just use the viewHolder
viewHolder = (Holder) convertView.getTag();
}
viewHolder.student_profile_fee_status.setText(student_list.get(postion).getStatus());
viewHolder.student_profile_ReceiptIssuedDate.setText(student_list.get(postion).getReceiptIssuedDate());
viewHolder.student_profile_ReceiptIssuedNumber.setText(student_list.get(postion).getReceiptIssuedNumber());
viewHolder.student_profile_FeeReceivedDate.setText(student_list.get(postion).getFeeReceivedDate());
viewHolder.student_profile_Fee_Amount.setText(student_list.get(postion).getAmount());
viewHolder.student_profile_Fee_Description.setText(student_list.get(postion).getFeeDescription());
convertView.setTag(viewHolder);
return convertView;
}
class Holder {
TextView student_profile_fee_status;
TextView student_profile_ReceiptIssuedDate;
TextView student_profile_ReceiptIssuedNumber;
TextView student_profile_FeeReceivedDate;
TextView student_profile_Fee_Amount;
TextView student_profile_Fee_Description;
}
}
费
public class Fee extends Fragment /*implements View.OnClickListener */ {
LinearLayout receipt1, receipt2, receipt3, receipt4;
LinearLayout receipt1detail, receipt2detail, receipt3detail, receipt4detail;
LinearLayout DescriptionAmount;
TextView statustextView;
ListView listViewfees, listviewfeedetail;
List<StudentFeeInformation> yourData = new ArrayList<StudentFeeInformation>();
public static final String Navigation_URL = "http://192.168.100.5:84/Api/financeApi/getAllFees";
String Amount;
String Descriptionlist, status, DateofReceiptIssued, ReceiptNumber, FeeReceivedDate;
String master_id;
LinearLayout linearLayout;
// View view1;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.student_fees_listview, container, false);
inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// view1 = inflater.inflate(R.layout.student_fees_description_data, null);
// linearLayout = (LinearLayout) view1.findViewById(R.id.student_profile_fee_linearlayout1);
// view1 = inflater.inflate(R.layout.student_fees_description_data, container, false);
setHasOptionsMenu(true);
receipt1 = (LinearLayout) view.findViewById(R.id.linear_receipt1_fee);
// receipt4 = (LinearLayout) view.findViewById(R.id.linear_receipt4_fee);
// receipt1detail = (LinearLayout) view.findViewById(R.id.receipt1_fee);
// receipt2detail = (LinearLayout) view.findViewById(R.id.receipt2_fee);
// receipt3detail = (LinearLayout) view.findViewById(R.id.receipt3_fee);
// receipt4detail = (LinearLayout) view.findViewById(R.id.receipt4_fee);
// receipt1.setOnClickListener(this);
// receipt2.setOnClickListener(this);
// receipt3.setOnClickListener(this);
// receipt4.setOnClickListener(this);
// receipt1detail.setVisibility(View.VISIBLE);
// receipt2detail.setVisibility(View.GONE);
// receipt3detail.setVisibility(View.GONE);
// receipt4detail.setVisibility(View.GONE);
statustextView = (TextView) view.findViewById(R.id.student_profile_fee_status);
SessionManagement sessionManagement = new SessionManagement(getContext());
master_id = sessionManagement.getMasterId();
listViewfees = (ListView) view.findViewById(R.id.list_student_fees);
// listviewfeedetail = (ListView) view.findViewById(R.id.listtest);
// DescriptionAmount = (LinearLayout) view.findViewById(R.id.student_profile_fee_linearlayout1);
// DescriptionAmount.addView(view);
getUsersListData();
return view;
}
private void getUsersListData() {
String URL = Navigation_URL + "?id=" + master_id;
StringRequest stringRequest = new StringRequest(Request.Method.GET, URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
ArrayList<StudentFeeInformation> student_list = new ArrayList<>();
ArrayList<FeeDescriptionStudent> student_list_description = new ArrayList<>();
JSONArray jArray = new JSONArray(response);
// studentFeeInformation = new StudentFeeInformation(response);
for (int i = 0; i < jArray.length(); i++) {
JSONObject jsonObject = jArray.getJSONObject(i);
status = jsonObject.getString("Status");
DateofReceiptIssued = jsonObject.getString("DateOfReciept").substring(0, 10);
ReceiptNumber = jsonObject.getString("RecieptNo");
FeeReceivedDate = jsonObject.getString("recivedDate").substring(0, 10);
String Description = jsonObject.getString("Description");
JSONArray jArray1 = new JSONArray(Description);
for (int j = 0; j < jArray1.length(); j++) {
JSONObject jsonObjectinner = jArray1.getJSONObject(j);
Descriptionlist = jsonObjectinner.getString("des");
Amount = jsonObjectinner.getString("Amount");
// TextView txtQuestion = (TextView) view1.findViewById(R.id.student_profile_fee_description);
// TextView tx = (TextView) view1.findViewById(R.id.student_profile_fee_amount);
// System.out.println(txtQuestion);
// System.out.println(tx);
// txtQuestion.setText(Descriptionlist);
// tx.setText(Amount);
// linearLayout.addView(view1);
Descriptionlist = jsonObjectinner.getString("des");
Amount = jsonObjectinner.getString("Amount");
}
student_list.add(new StudentFeeInformation(status, DateofReceiptIssued, ReceiptNumber, FeeReceivedDate, Descriptionlist, Amount));
//student_list.add(new StudentFeeInformation(status, DateofReceiptIssued, ReceiptNumber, FeeReceivedDate));
}
System.out.println("student_list size:" + student_list.size());
CustomFeeListStudentAdapter customFeeListStudentAdapter = new CustomFeeListStudentAdapter(getActivity(), student_list);
listViewfees.setAdapter(customFeeListStudentAdapter);
} catch (JSONException e) {
System.out.println("This is not good");
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// Toast.makeText(view.Fee.this, error.toString(), Toast.LENGTH_LONG).show();
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
return headers;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(getContext());
requestQueue.add(stringRequest);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// TODO Auto-generated method stub
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.dashboard, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// handle item selection
switch (item.getItemId()) {
case R.id.action_settings:
// do s.th.
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
我看过很多ExpandableListView以及TableView的例子 但无法将项目显示为listView.I已使用线性布局 代替ListView,但只显示了一个JSON数据 错误我无法得到它。
logcat的
03-29 16:52:20.023 1558-1569/system_process I/WindowManager: Destroying surface Surface(name=com.example.user.mis/com.example.user.mis.activity.Login) called by com.android.server.wm.WindowStateAnimator.destroySurface:2014 com.android.server.wm.WindowStateAnimator.destroySurfaceLocked:881 com.android.server.wm.WindowState.destroyOrSaveSurface:2073 com.android.server.wm.AppWindowToken.destroySurfaces:363 com.android.server.wm.AppWindowToken.notifyAppStopped:389 com.android.server.wm.WindowManagerService.notifyAppStopped:4456 com.android.server.am.ActivityStack.activityStoppedLocked:1252 com.android.server.am.ActivityManagerService.activityStopped:6895
03-29 16:52:22.656 11984-11984/com.example.user.mis I/System.out: student_list size:3
03-29 16:52:22.656 11984-11984/com.example.user.mis I/System.out: 3
03-29 16:52:22.656 11984-11984/com.example.user.mis I/System.out: 3
03-29 16:52:22.672 11984-11984/com.example.user.mis I/System.out: 3
03-29 16:52:22.672 11984-11984/com.example.user.mis I/System.out: 3
03-29 16:52:22.676 11984-11984/com.example.user.mis D/HomeTab_adapter: @@ postion:0 getTeacherNameLate Charge
03-29 16:52:22.677 11984-11984/com.example.user.mis D/HomeTab_adapter: @@ postion:1 getTeacherNameMonthly Fee
03-29 16:52:22.678 11984-11984/com.example.user.mis D/HomeTab_adapter: @@ postion:2 getTeacherNameExtra Charge
03-29 16:52:22.678 11984-11984/com.example.user.mis I/System.out: 3
03-29 16:52:22.679 11984-11984/com.example.user.mis D/HomeTab_adapter: @@ postion:0 getTeacherNameLate Charge
03-29 16:52:22.682 11984-11984/com.example.user.mis D/HomeTab_adapter: @@ postion:1 getTeacherNameMonthly Fee
03-29 16:52:22.684 11984-11984/com.example.user.mis D/HomeTab_adapter: @@ postion:2 getTeacherNameExtra Charge
03-29 16:52:23.039 11984-11984/com.example.user.mis I/System.out: 3
03-29 16:52:23.039 11984-11984/com.example.user.mis I/System.out: 3
03-29 16:52:23.041 11984-11984/com.example.user.mis D/HomeTab_adapter: @@ postion:0 getTeacherNameLate Charge
03-29 16:52:23.042 11984-11984/com.example.user.mis D/HomeTab_adapter: @@ postion:1 getTeacherNameMonthly Fee
03-29 16:52:23.042 11984-11984/com.example.user.mis D/HomeTab_adapter: @@ postion:2 getTeacherNameExtra Charge
03-29 16:52:23.042 11984-11984/com.example.user.mis I/System.out: 3
答案 0 :(得分:0)
从该截图看来,没有必要使用listview 在listview中。你可以使用Section header listview 或者只使用listview并为第一项设置背景颜色 适配器。
在适配器中,根据条件,您可以隐藏和显示子视图。
你必须在for循环中添加student_list.add,如下所示:
for (int j = 0; j < jArray1.length(); j++) {
JSONObject jsonObjectinner = jArray1.getJSONObject(j);
Descriptionlist = jsonObjectinner.getString("des");
Amount = jsonObjectinner.getString("Amount");
student_list.add(new StudentFeeInformation(status, DateofReceiptIssued, ReceiptNumber, FeeReceivedDate, Descriptionlist, Amount));
}
<强>布局:强>
费用 - &gt;您应该在活动布局列表视图的顶部添加此费用标题,而不是适配器布局。
在适配器中:
第一项:使用水平线性布局作为第一项,并将背景颜色设置为绿色。
第二项:使用水平线性布局作为第二项,并将背景颜色设置为银色或浅透明色。
第三项:使用水平线性布局作为第三项。
对于所有子项目:第四,第五和第六项使用水平线性布局,并在其中放置两个文本视图。
答案 1 :(得分:0)
您需要做的就是为父母1和6定义孩子。对于其他职位,您可以简单地将他们视为没有孩子的父母。
您需要定义正确的模型类并在模型中传递数据。