我正在构建一个用于项目时间管理的应用程序,现在我陷入困境,我想显示当前项目的所有收集信息,但每次我更改一个EditView或Button-Text时,整个视图都会被重新加载并且仅显示最后一次更改。不幸的是,我已经没有想法如何描述这个问题,以找到答案,所以我在这里问。 ;) 我的问题是:每次更改一个元素时,如何保持视图不重新加载,因为重新加载会重置所有其他元素。
查看:
<LinearLayout 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:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/labelJobDatum"
android:text="Datum:"/>
<Button
android:id="@+id/btnJobDatum"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/labelJobDatum"
android:onClick="btnDatumClicked"
android:text=""/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Startzeit:"/>
<Button
android:id="@+id/btnStartZeit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="btnStartZeitClicked"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Stopzeit:"/>
<Button
android:id="@+id/btnStopZeit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="btnStopZeitClicked"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Pausenzeit:"/>
<Button
android:id="@+id/btnPausenZeit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="btnPausenZeitClicked"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Dauer(tats.):"/>
<Button
android:id="@+id/btnDauerTats"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="btnDauerTatsClicked"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Dauer(ber.):"/>
<Button
android:id="@+id/btnDauerBer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="btnDauerBerClicked"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Mitarbeiter:"/>
<EditText
android:id="@+id/txtMitarbeiter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Kunde:"/>
<Spinner
android:id="@+id/spnKunde"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/btn_dropdown"
android:spinnerMode="dropdown" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Projekt:"/>
<Spinner
android:id="@+id/spnProjekt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/btn_dropdown"
android:spinnerMode="dropdown" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Projektabschnitt:"/>
<Spinner
android:id="@+id/spnProjektabschnitt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/btn_dropdown"
android:spinnerMode="dropdown" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Aufgabe:"/>
<Spinner
android:id="@+id/txtAufgabe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/btn_dropdown"
android:spinnerMode="dropdown" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/txtAufgabenIDLabel"
android:text="Aufgaben ID: "/>
<TextView
android:id="@+id/txtAufgabenID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/txtAufgabenIDLabel"
android:text=""/>
<Button
android:id="@+id/btnaufgabenIDNeu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/txtAufgabenID"
android:onClick="btnNeuAufgabenIDClicked"
android:text="neu"/>
</RelativeLayout>
<CheckBox
android:id="@+id/chkReisezeit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reisezeit " />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Beschreibung: "/>
<EditText
android:id="@+id/txtBeschreibung"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<CheckBox
android:id="@+id/chkFreigabePV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Freigabe durch PV "/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Rechnungstext:"/>
<EditText
android:id="@+id/txtRechnungstext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Bemerkung:"/>
<EditText
android:id="@+id/txtBemerkung"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Tätigkeit:"/>
<EditText
android:id="@+id/txtTaetigkeit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btnTaetigkeitAbbrechen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Abbrechen"/>
<Button
android:id="@+id/btnTaetigkeitOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/btnTaetigkeitAbbrechen"
android:text="Ok"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
如果我做了一个
Button btnDatum = (Button)this.findViewById(R.id.btnJobDatum);
btnDatum.setText(Datum);
只重新加载视图,只有btnDatum有文本,所有其他元素都是空的。
说明问题:
如果我单击其中一个按钮,则会更改此按钮文本。我希望第一个按钮在我单击第二个按钮后保留其文本,但每次单击一个按钮时,此按钮是唯一一个有文本的按钮。
答案 0 :(得分:0)
您可能忘记在XML文件末尾关闭LinearLayout标记。
在XML文件末尾添加</LinearLayout>
可能有帮助吗?
此外,您没有为任何按钮android:text=""
设置默认文本,因此所有按钮上都没有任何文字(如您所说,为空)