Android Studio输出文本始终为“来自C ++的问候" [英] Android Studio output text always 'Hello from C++'

查看:101
本文介绍了Android Studio输出文本始终为“来自C ++的问候"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正面临这个奇怪的问题,我在activity_main.xml中创建了textview并将文本设置为:android:text="Oh my god" 但是无论我输入什么文本,应用程序屏幕中的输出都是:

I'm facing this weird problem, I've created a textview in activity_main.xml and set text as: android:text="Oh my god" But no matter to whatever the text I put, the output in app screen is:

你好,来自C ++

Hello from C++

实际上,文本的位置根据我的设置而变化,但是不幸的是,文本始终保持不变.我试着删除并再次添加textview,但没有任何变化.

In fact, the position of text changes according to my setting but the text always remains unfortunately unchanged. I've tried removing and again adding textview but no change.

MainActivity.java:

MainActivity.java:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    // Example of a call to a native method
    TextView tv = (TextView) findViewById(R.id.sample_text);
    tv.setText(stringFromJNI());
    }

activity_main.xml:

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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=".MainActivity">

    <TextView
        android:id="@+id/sample_text"
        android:layout_width="147dp"
        android:layout_height="76dp"
        android:layout_marginStart="248dp"
        android:layout_marginTop="16dp"
        android:text="Oh my god"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

PS:有些人有同样的问题,但尚未得到答复.

PS: Some guy has this same problem but wasn't answered yet.

推荐答案

这是您的问题:

tv.setText(stringFromJNI());

这会将文本设置为stringFromJNI()返回的内容,从而替换您在XML中定义的内容.

That sets the text to whatever stringFromJNI() returns, replacing what you define in the XML.

如果要更改显示的文本,请修改本机方法以返回所需的内容,删除编程设置,或更改在代码中设置的文本.

If you want to change the text that is displayed, either modify the native method to return what you want, remove the programmatic setting, or change what you set the text to in your code.

这篇关于Android Studio输出文本始终为“来自C ++的问候"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆