使用Android Studio时遇到一个奇怪的问题。我无法设置TextView(tAx)的文本,引用不是“空指针”,而且我没有错误或异常,只是我没有'看文字。
我的主要课程:
@Override
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.main);
super.onCreate(savedInstanceState);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
tAx = (TextView) findViewById(R.id.Ax);
tAx.setText("prova");
// Set up the custom title
mTitle = (TextView) findViewById(R.id.title_left_text);
// mTitle.setText(R.string.app_name);
mTitle = (TextView) findViewById(R.id.title_right_text);
// Get local Bluetooth adapter
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
// If the adapter is null, then Bluetooth is not supported
if (mBluetoothAdapter == null) {
Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
finish();
return;
}
}
XML Main:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1">
<TextView android:id="@+id/Ax"
android:layout_width="198dp"
android:layout_height="38dp"
android:textSize="20dp"
android:visibility="visible"
android:background="#ffffffff"
android:textColor="#fff"
/>
</LinearLayout>
谢谢你!
更新
谢谢你!所以现在我可以设置文本但只有一次(第一次)!在另一个类中,我尝试通过引用设置文本(使用静态和公共的税务参考),但它们不会更改,但仍然是第一个,并且在控制台上的Android Studio打印错误:
只有创建视图层次结构的原始线程才能触及它 视图
RemoteBluetooth.tAx.setText(String.valueOf(Ax));
答案 0 :(得分:1)
您可以使用以小写字母开头的ID来修复错误。 Android似乎有一个问题,id以大写字母开头。
答案 1 :(得分:0)
删除android:weightSum="1"
并检查其余xml
个文件,因为当xml
文件中出现语法错误时会发生这种情况。
答案 2 :(得分:0)
你只是在白色上绘制白色。将{{posts[0].campaigns.campaign[0].id}}
属性更改为其他内容。
答案 3 :(得分:0)
您将背景和文字颜色设置为相同的颜色值,诅咒您无法看到任何变化。
将文本颜色更改为与背景不同的颜色。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1">
<TextView
android:id="@+id/Ax"
android:layout_width="198dp"
android:layout_height="38dp"
android:background="#ffffffff"
android:textColor="#000"
android:textSize="20dp"
android:visibility="visible" />
</LinearLayout>