Answer the question
In order to leave comments, you need to log in
How can I fix the error in the "hello world" code?
I want that when I click on my button in the application, the text field changes to my custom text. This is probably a simple task, but I need your help!
here is the MainActivity.java script
package com.example.maratmkhitaryan.maratfirsapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.io.Console;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onMyButtonClick()
{
TextView textElemetnt = (TextView) findViewById(R.id.textView);
textElemetnt.setText("Hello programm has stopped")
System.out.println("Hello world");
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.maratmkhitaryan.maratfirsapp.MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Marat Help!"
android:id="@+id/BuutonHelp"
android:onClick="onMyButtonClick"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:layout_alignParentEnd="false"
android:layout_alignParentStart="false"
android:allowUndo="false"
android:autoText="false" />
</RelativeLayout>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question