活动 XML 的更改在我运行应用程序时未在我的设备上显示

huangapple go评论85阅读模式
英文:

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:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;ScrollView xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
    xmlns:tools=&quot;http://schemas.android.com/tools&quot;
    android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;match_parent&quot;
    android:orientation=&quot;horizontal&quot;
    tools:context=&quot;.CrmActivity&quot;&gt;

    &lt;androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width=&quot;match_parent&quot;
        android:layout_height=&quot;wrap_content&quot;&gt;
           

        &lt;androidx.constraintlayout.widget.Guideline
            android:id=&quot;@+id/guideline5&quot;
            android:layout_width=&quot;wrap_content&quot;
            android:layout_height=&quot;wrap_content&quot;
            android:orientation=&quot;vertical&quot;
            app:layout_constraintGuide_percent=&quot;0.5&quot; /&gt;

        &lt;androidx.constraintlayout.widget.ConstraintLayout
            android:id=&quot;@+id/cl_2&quot;
            android:layout_width=&quot;0dp&quot;
            android:layout_height=&quot;wrap_content&quot;
            android:background=&quot;@drawable/linearlayout_background&quot;
            android:padding=&quot;10dp&quot;
            app:layout_constraintEnd_toStartOf=&quot;@+id/guideline5&quot;
            app:layout_constraintHorizontal_bias=&quot;0.0&quot;
            app:layout_constraintStart_toStartOf=&quot;parent&quot;
            app:layout_constraintTop_toBottomOf=&quot;@+id/cl_1&quot;&gt;

            &lt;TextView
                android:id=&quot;@+id/tv_kontakt1&quot;
                android:layout_width=&quot;0dp&quot;
                android:layout_height=&quot;wrap_content&quot;
                android:layout_alignParentStart=&quot;true&quot;
                android:layout_alignParentTop=&quot;true&quot;
                android:layout_alignParentEnd=&quot;true&quot;
                android:gravity=&quot;center&quot;
                android:text=&quot;Kontakt 1&quot;
                android:textAllCaps=&quot;true&quot;
                android:textSize=&quot;20dp&quot;
                android:textStyle=&quot;bold&quot;
                app:layout_constraintEnd_toEndOf=&quot;parent&quot;
                app:layout_constraintStart_toStartOf=&quot;@+id/et_k1_nev&quot;
                app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;

            &lt;EditText
                android:id=&quot;@+id/et_k1_nev&quot;
                android:layout_width=&quot;0dp&quot;
                android:layout_height=&quot;wrap_content&quot;
                android:layout_below=&quot;@+id/tv_kontakt1&quot;
                android:layout_marginTop=&quot;8dp&quot;
                android:ems=&quot;10&quot;
                android:hint=&quot;N&#233;v&quot;
                android:inputType=&quot;textPersonName&quot;
                app:layout_constraintEnd_toEndOf=&quot;parent&quot;
                app:layout_constraintStart_toStartOf=&quot;parent&quot;
                app:layout_constraintTop_toBottomOf=&quot;@+id/tv_kontakt1&quot; /&gt;  
           
        &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;

        &lt;androidx.constraintlayout.widget.ConstraintLayout
            android:id=&quot;@+id/cl_3&quot;
            android:layout_width=&quot;0dp&quot;
            android:layout_height=&quot;wrap_content&quot;
            android:background=&quot;@drawable/linearlayout_background&quot;
            android:padding=&quot;10dp&quot;
            app:layout_constraintEnd_toEndOf=&quot;parent&quot;
            app:layout_constraintStart_toEndOf=&quot;@+id/cl_2&quot;
            app:layout_constraintTop_toBottomOf=&quot;@+id/cl_1&quot;&gt;

            &lt;TextView
                android:id=&quot;@+id/tv_kontakt2&quot;
                android:layout_width=&quot;0dp&quot;
                android:layout_height=&quot;wrap_content&quot;
                android:layout_alignParentStart=&quot;true&quot;
                android:layout_alignParentTop=&quot;true&quot;
                android:gravity=&quot;center&quot;
                android:text=&quot;Kontakt 2&quot;
                android:textAllCaps=&quot;true&quot;
                android:textSize=&quot;20dp&quot;
                android:textStyle=&quot;bold&quot;
                app:layout_constraintEnd_toEndOf=&quot;parent&quot;
                app:layout_constraintStart_toStartOf=&quot;parent&quot;
                app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;

            &lt;EditText
                android:id=&quot;@+id/et_k2_nev&quot;
                android:layout_width=&quot;0dp&quot;
                android:layout_height=&quot;wrap_content&quot;
                android:layout_below=&quot;@+id/tv_kontakt2&quot;
                android:layout_marginTop=&quot;8dp&quot;
                android:ems=&quot;10&quot;
                android:hint=&quot;N&#233;v&quot;
                android:inputType=&quot;textPersonName&quot;
                app:layout_constraintEnd_toEndOf=&quot;parent&quot;
                app:layout_constraintStart_toStartOf=&quot;parent&quot;
                app:layout_constraintTop_toBottomOf=&quot;@+id/tv_kontakt2&quot; /&gt;  
            

        &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;   
        

        &lt;Button
            android:id=&quot;@+id/button4&quot;
            android:layout_width=&quot;0dp&quot;
            android:layout_height=&quot;wrap_content&quot;
            android:layout_marginStart=&quot;4dp&quot;
            android:layout_marginTop=&quot;4dp&quot;
            android:layout_marginEnd=&quot;8dp&quot;
            android:onClick=&quot;CRM_gombok_onClick&quot;
            android:text=&quot;OK&quot;
            android:textSize=&quot;10sp&quot;
            app:layout_constraintEnd_toEndOf=&quot;parent&quot;
            app:layout_constraintHorizontal_bias=&quot;1.0&quot;
            app:layout_constraintStart_toStartOf=&quot;@+id/guideline5&quot;
            app:layout_constraintTop_toBottomOf=&quot;@+id/button2&quot; /&gt;

        &lt;Button
            android:id=&quot;@+id/button5&quot;
            android:layout_width=&quot;0dp&quot;
            android:layout_height=&quot;wrap_content&quot;
            android:layout_marginStart=&quot;4dp&quot;
            android:layout_marginTop=&quot;4dp&quot;
            android:layout_marginEnd=&quot;8dp&quot;
            android:onClick=&quot;CRM_gombok_onClick&quot;
            android:text=&quot;Exit&quot;
            android:textSize=&quot;10sp&quot;
            app:layout_constraintEnd_toEndOf=&quot;parent&quot;
            app:layout_constraintHorizontal_bias=&quot;0.0&quot;
            app:layout_constraintStart_toStartOf=&quot;@+id/guideline5&quot;
            app:layout_constraintTop_toBottomOf=&quot;@+id/button4&quot; /&gt;   

    &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;

&lt;/ScrollView&gt;

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(&quot;felhasznalonev&quot;);
        kivalasztottPartner = (Partner) extras.getSerializable(&quot;kivalasztottPartner&quot;);
    }

    db = new DatabaseHelper(getApplicationContext());

    VEVO_INFO vevo_info = db.getVEVO_INFO(kivalasztottPartner);

    if (Build.VERSION.SDK_INT &gt;= 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 文件,就能得到正确的结果... 我没有选择那个! 活动 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! 活动 XML 的更改在我运行应用程序时未在我的设备上显示

huangapple
  • 本文由 发表于 2020年10月26日 22:30:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/64539126.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定