我在listView中有ListView我有文本,文本,linearLayout.LinearLayout有另一个视图在ListView中膨胀。我有一个主 View = view ,返回显示listView,但我我正在努力在LinearLayout上返回view1的值。
费用等级
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);
view1 = inflater.inflate(R.layout.student_fees_description_data, container, false);
**how can view1 be returned**
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);
linearLayout = (LinearLayout) view1.findViewById(R.id.student_profile_fee_linearlayout1);
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);
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);
}
fragment_fee
<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>
<LinearLayout
android:id="@+id/student_profile_fee_linearlayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- <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>
线性布局要膨胀 的 student_fees_description_data
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/student_profile_fee_linearlayout"
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>
如何返回两个视图,一个视图是否膨胀到linearLayout?
答案 0 :(得分:0)
找到解决方案:
1.去除:
view1 = inflater.inflate(R.layout.student_fees_description_data, container, false);
2。使用以下代码扩充view1布局:
LayoutInflater inflater =(LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view1 = inflater.inflate(R.layout.student_fees_description_data, container, false);