英文:
The changes of the activity xml don't appear on my device when I run the app
问题
我是安卓开发的新手,我有一个继承来的项目。
它运行得很好,但是我遇到了一个烦人的问题。
如果我在活动的 XML 上做了任何更改,当我运行应用程序时,这些更改不会显示在我的设备上。它们只会出现在 XML 的设计选项卡中。
我的更改:
- 覆盖了文本视图的文本属性,但新文本不会显示...
- 添加了一个新按钮(button5),但不会显示...(旧的/继承的按钮(button4)显示正常)
这是我的 XML 代码的一小部分:
<!-- 在这里插入你的 XML 代码 -->
这是我的 Java 代码的相关部分:
// 在这里插入你的 Java 代码
我只提供了你要翻译的内容,如果还有其他问题或需要进一步的帮助,请随时告诉我。
英文:
I'm newbie in the android development, and I have an inherited project.
It works quite well, but I have an annoying problem with it.
If I changed anything on my activity xml, the changes don't appear on my device when I run the app. They appears just on the Design tab of the xml.
My changes:
- Overwriting the text property of a textview, but the new text doesn't appear...
- Adding new button (button5), but doesn't appear... (The older/inherited button (button4) appears appropriately)
Here's a small piece of my xml code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
android:orientation="horizontal"
tools:context=".CrmActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.5" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/cl_2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/linearlayout_background"
android:padding="10dp"
app:layout_constraintEnd_toStartOf="@+id/guideline5"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cl_1">
<TextView
android:id="@+id/tv_kontakt1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:gravity="center"
android:text="Kontakt 1"
android:textAllCaps="true"
android:textSize="20dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/et_k1_nev"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/et_k1_nev"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_kontakt1"
android:layout_marginTop="8dp"
android:ems="10"
android:hint="Név"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_kontakt1" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/cl_3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/linearlayout_background"
android:padding="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/cl_2"
app:layout_constraintTop_toBottomOf="@+id/cl_1">
<TextView
android:id="@+id/tv_kontakt2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="Kontakt 2"
android:textAllCaps="true"
android:textSize="20dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/et_k2_nev"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_kontakt2"
android:layout_marginTop="8dp"
android:ems="10"
android:hint="Név"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_kontakt2" />
</androidx.constraintlayout.widget.ConstraintLayout>
<Button
android:id="@+id/button4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="8dp"
android:onClick="CRM_gombok_onClick"
android:text="OK"
android:textSize="10sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="@+id/guideline5"
app:layout_constraintTop_toBottomOf="@+id/button2" />
<Button
android:id="@+id/button5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="8dp"
android:onClick="CRM_gombok_onClick"
android:text="Exit"
android:textSize="10sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/guideline5"
app:layout_constraintTop_toBottomOf="@+id/button4" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
Here's a related piece of my java code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_crm);
Bundle extras = getIntent().getExtras();
if (extras != null) {
felhasznalonev = extras.getString("felhasznalonev");
kivalasztottPartner = (Partner) extras.getSerializable("kivalasztottPartner");
}
db = new DatabaseHelper(getApplicationContext());
VEVO_INFO vevo_info = db.getVEVO_INFO(kivalasztottPartner);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION}, 11);
}
locationManager = (LocationManager) CrmActivity.this.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setPowerRequirement(Criteria.POWER_HIGH);
criteria.setAltitudeRequired(false);
criteria.setSpeedRequired(false);
criteria.setCostAllowed(true);
criteria.setBearingRequired(false);
criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
criteria.setVerticalAccuracy(Criteria.ACCURACY_HIGH);
provider = locationManager.getBestProvider(criteria, false);
initViews();
fillViewsWithKnownDatas(vevo_info);
}
private void initViews() {
et_k1_nev = findViewById(R.id.et_k1_nev);
et_k2_nev = findViewById(R.id.et_k2_nev);
}
private void fillViewsWithKnownDatas(VEVO_INFO vevo_info) {
if(!vevo_info.getK1_NEV().isEmpty()){
et_k1_nev.setText(vevo_info.getK1_NEV());
}
if(!vevo_info.getK2_NEV().isEmpty()){
et_k2_nev.setText(vevo_info.getK2_NEV());
}
}
答案1
得分: 0
这只是一个愚蠢的误解。解决方案非常简单,只需从正确的布局文件夹中选择正确的 XML 文件,就能得到正确的结果... 我没有选择那个!
英文:
It was a stupid misunderstanding. The solution is very simple, just choose the right xml from the right layout folder for the right result... I didn't choose that!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论