Home>

Thanks for your attention.
I'm studying on Android Stdio
https://anharu.keiji.io/lesson1/step9/
I'm trying to make a calculator on the above site
I am struggling because the numeric keypad is not displayed well in XML

<? xml version = "1.0" encoding = "utf-8"?>
<TableLayout xmlns: android = "http://schemas.android.com/apk/res/android"
    android: layout_width = "match_parent"
    android: layout_height = "match_parent"
    android: stretchColumns = "0,1,2,3">
    <TableRow
       
        android: layout_height = "wrap_content"
        android: layout_width = "match_parent"
        >
        <Button
            android: id = "@ + id/button_7"
           
            android: layout_width = "wrap_content"
            android: layout_height = "wrap_content"
            android: text = "7" />
        <Button
            android: id = "@ + id/button_8"
           
            android: layout_width = "wrap_content"
            android: layout_height = "wrap_content"
            android: text = "8" />
    <Button
        android: id = "@ + id/button_9"
       
        android: layout_width = "wrap_content"
        android: layout_height = "wrap_content"
        android: text = "9" />
    <Button
        android: id = "@ + id/button_divide"
       
        android: layout_width = "wrap_content"
        android: layout_height = "wrap_content"
        android: text = "÷" />
</TableRow>
<TableRow
   
    android: layout_width = "match_parent"
    android: layout_height = "wrap_content">
    <Button
        android: id = "@ + id/button_4"
       
        android: layout_width = "wrap_content"
        android: layout_height = "wrap_content"
        android: text = "4"/​​>
    <Button
        android: id = "@ + id/button_5"
       
        android: layout_width = "wrap_content"
        android: layout_height = "wrap_content"
        android: text = "5"
        />
    <Button
        android: id = "@ + id/button_6"
       
        android: layout_width = "wrap_content"
        android: layout_height = "wrap_content"
        android: text = "6"
        />
    <Button
        android: id = "@ + id/button_multiply"
       
        android: layout_width = "wrap_content"
        android: layout_height = "wrap_content"
        android: text = "×"
        />
</TableRow>
<TableRow
   
    android: layout_width = "match_parent"
    android: layout_height = "wrap_content">
    <Button
        android: id = "@ + id/button_1"
       
        android: layout_width = "wrap_content"
        android: layout_height = "wrap_content"
        android: text = "1" />
    <Button
        android: id = "@ + id/button_2"
       
        android: layout_width = "wrap_content"
        android: layout_height = "wrap_content"
        android: text = "2"
        />
    <Button
        android: id = "@ + id/button_3"
       
        android: layout_width = "wrap_content"
        android: layout_height = "wrap_content"
        android: text = "3"
        />
    <Button
        android: id = "@ + id/button_subtract"
       
        android: layout_width = "wrap_content"
        android: layout_height = "wrap_content"
        android: text = "-"
        /></TableRow>
<TableRow
   
    android: layout_width = "match_parent"
    android: layout_height = "wrap_content"
    >
    <Button
        android: id = "@ + id/button_dot"
       
        android: layout_width = "wrap_content"
        android: layout_height = "wrap_content"
        android: text = "."
        />
    <Button
        android: id = "@ + id/button_0"
       
        android: layout_width = "wrap_content"
        android: layout_height = "wrap_content"
        android: text = "0"
        />
    <Button
        android: id = "@ + id/button_equal"
       
        android: layout_width = "wrap_content"
        android: layout_height = "wrap_content"
        android: text = "="
        />
    <Button
        android: id = "@ + id/button_add"
       
        android: layout_width = "wrap_content"
        android: layout_height = "wrap_content"
        android: text = "+"
        />
    </TableRow>
</TableLayout>Code


Is something wrong

Activity below

package com.webserva.wings.android.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
    TextView textview;
    EditText editText;
    Button button;
    View.OnClickListener buttonListener = new View.OnClickListener () {
        @Override
        public void onClick (View view) {
            textview.setText (editText.getText (). toString ());
            String string = editText.getText (). ToString ();
            Log.d ("EditTextTest", string);
        }
    };
    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate (savedInstanceState);
        setContentView (R.layout.activity_main);
        textview = findViewById (R.id.textview);
        editText = findViewById (R.id.edittext);
        button = findViewById (R.id.button);
        button.setOnClickListener (buttonListener);
    }
}


main XML

<? 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 = ". MainActivity">->
    <TextView
        android: id = "@ + id/textview"
        android: layout_width = "wrap_content"
        android: layout_height = "wrap_content"
        android: text = "Hello World!" />
    <EditText
        android: id = "@ + id/edittext"
        android: layout_width = "match_parent"
        android: layout_height = "wrap_content"
        android: layout_below = "@ + id/textview" />

    <Button
        android: id = "@ + id/button"
        android: layout_width = "match_parent"
        android: layout_height = "wrap_content"
        android: layout_below = "@ + id/edittext"
        android: text = "button" />
</RelativeLayout>


  • Answer # 1

    For the sites I have referenced,

    <include
            layout = "@ layout/ten_key"
            android: layout_width = "match_parent"
            android: layout_height = "wrap_content"
            android: layout_below = "@ id/button"
            />


    However, this is not found in the "main XML" presented. This includes the meaning of embedding the contents described in a separate file, and it seems that the tenkey is displayed by embedding ten_key.xml described for the tenkey here. Since there is no such description, there will be no place to display the contents of ten_key.xml.