その中のボタンをクリックすると、フルスクリーンのフラグメントを追加するアクティビティーがあります。 これが私の活動のXMLです:フラグメントが追加されたときにアクティビティーのレイアウトが変更されない
public void showInspectionDatesFragment(View v)
{
InspectionDatesFragment f = InspectionDatesFragment.newInstance(null);
Utilities.addFragment(R.id.addVehicleContainer, f, null, getSupportFragmentManager());
}
Utilities.addFragment
単にフラグメントのトランザクションを実行する(それがFragmentTransaction
オブジェクトを作成し、通話:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="clyky.cartracker.activities.AddVehicleActivity"
android:id="@+id/addVehicleContainer">
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lblPlate"
android:text="Targa"
android:labelFor="@+id/txtPlate"/>
<EditText
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/txtPlate"
android:inputType="text"
android:hint="Targa del veicolo"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lblKm"
android:text="Chilometri"
android:labelFor="@+id/txtPlate"/>
<EditText
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/txtKm"
android:inputType="number"
android:hint="Chilometraggio"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/lblInUse"
android:labelFor="@+id/chckbxInUse"
android:text="In uso:"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chckbxInUse"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/lblInsuranceDate"
android:labelFor="@+id/txtInsuranceDate"
android:text="Data di assicurazione:"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txtInsuranceDate"
android:text=""/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/btnShowDatePickerForInsuranceDate"
android:onClick="showDatePicker"
android:text="Seleziona"
android:tag="0"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/lblMatriculationDate"
android:labelFor="@+id/txtMatriculationDate"
android:text="Data d'immatricolazione:"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txtMatriculationDate"
android:text=""/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/btnShowDatePickerForMatriculationDate"
android:onClick="showDatePicker"
android:text="Seleziona"
android:tag="1"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/lblEffectiveFuelEconomy"
android:labelFor="@+id/txtEffectiveFuelEconomy"
android:text="Consumo di carburante (km/l):"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txtEffectiveFuelEconomy"
android:inputType="number"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/lblMake"
android:labelFor="@+id/txtLastInspectionDate"
android:text="Produttore:"/>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/spnrMake"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/lblModel"
android:labelFor="@+id/spnrModel"
android:text="Modello:"/>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/spnrModel"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/lblTrim"
android:labelFor="@+id/spnrTrim"
android:text="Assetto:"/>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/spnrTrim"/>
</TableRow>
<TableRow>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnShowInspectionDates"
android:text="Aggiungi date di revisione"
android:onClick="showInspectionDatesFragment"/>
</TableRow>
<TableRow>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/btnSubmit"
android:onClick="submit"
android:text="Invia"/>
</TableRow>
</TableLayout>
これはbtnShowInspectionDates
がクリックされたときにフラグメントを変更する方法であり、 add
メソッドを呼び出し、トランザクションのコミットを実行します)。
これは私のInspectionDatesFragment
のレイアウトです:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/recycler_view_fragment_layout"/>
<Button
android:id="@+id/btnAddInspectionDate"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="+"/>
</LinearLayout>
recycler_view_fragment_layout
は単に私がRecyclerView
が含まれている他のレイアウトで基本レイアウトとしてこれを使用し、LinearLayout
内部RecyclerView
が含まれています。
btnShowInspectionDates
をクリックすると、携帯電話のレイアウトが変更されていないようです。私はデバッグを使用して、フラグメントが実際にはonCreatedView
にブレークポイントを入れて作成されているかどうかを確認しました。そして、はい、例外がスローされないので正常に作成されました。 logcatは有用なものを提供していないようですので、誰も私の問題を解決する方法を知っていますか?
ありがとうございます!
EDIT
は今、私は私のAddVehicleActivity
の以前のレイアウトを含むフラグメントを作成した、とbtnShowInspectionDates
がクリックされたときに私は2つのフラグメントを変更します。しかし、今私は別の問題がある:btnAddInspectionDate
は私のInspectionDatesFragment
に表示されていません:ビューは完全に白です。
inspection_dates_fragment_layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/recycler_view_fragment_layout"/>
<Button
android:id="@+id/btnAddInspectionDate"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="+"/>
</LinearLayout>