简体   繁体   中英

Why text displays in a button instead of textview?

How can it be, that then i launch this code, text changes in the button?? Explain please. i took recomendations from here . I need that the button has text "Click me" and the textview "Hello". instead of that i become nothing in the textview and "Hello" in the button.

In layout:

 <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="Click me" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="76dp" />

In Activity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_hello_android);

    TextView textView = (TextView) findViewById(R.id.textView1);
    textView.setText("Hello");

}

I had to clean the project. Thanks to all!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM