質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
XML

XMLは仕様の1つで、マークアップ言語群を構築するために使われています。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Q&A

解決済

1回答

2104閲覧

Android Studio テンキーXMLについて

gomakasu423

総合スコア31

XML

XMLは仕様の1つで、マークアップ言語群を構築するために使われています。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

0グッド

0クリップ

投稿2018/09/01 15:04

お世話になっております。
Android Stdio独学中です
https://anharu.keiji.io/lesson1/step9/
上記サイトで電卓を作るに挑戦しているのですが
XMLでテンキーがうまく表示されずに苦戦中です

XML

1<?xml version="1.0" encoding="utf-8"?> 2<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:stretchColumns="0,1,2,3"> 6 <TableRow 7 style="?attr/actionBarStyle" 8 android:layout_height="wrap_content" 9 android:layout_width="match_parent" 10 > 11 <Button 12 android:id="@+id/button_7" 13 style="?attr/buttonBarButtonStyle" 14 android:layout_width="wrap_content" 15 android:layout_height="wrap_content" 16 android:text="7"/> 17 <Button 18 android:id="@+id/button_8" 19 style="?attr/buttonBarButtonStyle" 20 android:layout_width="wrap_content" 21 android:layout_height="wrap_content" 22 android:text="8"/> 23 <Button 24 android:id="@+id/button_9" 25 style="?attr/buttonBarButtonStyle" 26 android:layout_width="wrap_content" 27 android:layout_height="wrap_content" 28 android:text="9"/> 29 <Button 30 android:id="@+id/button_divide" 31 style="?attr/buttonBarButtonStyle" 32 android:layout_width="wrap_content" 33 android:layout_height="wrap_content" 34 android:text="÷"/> 35</TableRow> 36 37<TableRow 38 style="?attr/actionBarStyle" 39 android:layout_width="match_parent" 40 android:layout_height="wrap_content"> 41 42 <Button 43 android:id="@+id/button_4" 44 style="?attr/buttonBarButtonStyle" 45 android:layout_width="wrap_content" 46 android:layout_height="wrap_content" 47 android:text="4"/> 48 49 <Button 50 android:id="@+id/button_5" 51 style="?attr/buttonBarButtonStyle" 52 android:layout_width="wrap_content" 53 android:layout_height="wrap_content" 54 android:text="5" 55 /> 56 <Button 57 android:id="@+id/button_6" 58 style="?attr/buttonBarButtonStyle" 59 android:layout_width="wrap_content" 60 android:layout_height="wrap_content" 61 android:text="6" 62 /> 63 <Button 64 android:id="@+id/button_multiply" 65 style="?attr/buttonBarButtonStyle" 66 android:layout_width="wrap_content" 67 android:layout_height="wrap_content" 68 android:text="×" 69 /> 70</TableRow> 71 72<TableRow 73 style="?attr/actionBarStyle" 74 android:layout_width="match_parent" 75 android:layout_height="wrap_content"> 76 <Button 77 android:id="@+id/button_1" 78 style="?attr/buttonBarButtonStyle" 79 android:layout_width="wrap_content" 80 android:layout_height="wrap_content" 81 android:text="1"/> 82 <Button 83 android:id="@+id/button_2" 84 style="?attr/buttonBarButtonStyle" 85 android:layout_width="wrap_content" 86 android:layout_height="wrap_content" 87 android:text="2" 88 /> 89 <Button 90 android:id="@+id/button_3" 91 style="?attr/buttonBarButtonStyle" 92 android:layout_width="wrap_content" 93 android:layout_height="wrap_content" 94 android:text="3" 95 /> 96 <Button 97 android:id="@+id/button_subtract" 98 style="?attr/buttonBarButtonStyle" 99 android:layout_width="wrap_content" 100 android:layout_height="wrap_content" 101 android:text="-" 102 /> 103</TableRow> 104 105<TableRow 106 style="?attr/actionBarStyle" 107 android:layout_width="match_parent" 108 android:layout_height="wrap_content" 109 > 110 <Button 111 android:id="@+id/button_dot" 112 style="?attr/buttonBarButtonStyle" 113 android:layout_width="wrap_content" 114 android:layout_height="wrap_content" 115 android:text="." 116 /> 117 <Button 118 android:id="@+id/button_0" 119 style="?attr/buttonBarButtonStyle" 120 android:layout_width="wrap_content" 121 android:layout_height="wrap_content" 122 android:text="0" 123 /> 124 <Button 125 android:id="@+id/button_equal" 126 style="?attr/buttonBarButtonStyle" 127 android:layout_width="wrap_content" 128 android:layout_height="wrap_content" 129 android:text="=" 130 /> 131 <Button 132 android:id="@+id/button_add" 133 style="?attr/buttonBarButtonStyle" 134 android:layout_width="wrap_content" 135 android:layout_height="wrap_content" 136 android:text="+" 137 /> 138 </TableRow> 139</TableLayout>コード

何か間違っていますでしょうか

下記 Activityです

java

1 2package com.webserva.wings.android.myapplication; 3 4import android.support.v7.app.AppCompatActivity; 5import android.os.Bundle; 6import android.util.Log; 7import android.view.View; 8import android.widget.Button; 9import android.widget.EditText; 10import android.widget.TextView; 11 12public class MainActivity extends AppCompatActivity { 13 TextView textview; 14 EditText editText; 15 Button button; 16 View.OnClickListener buttonListener = new View.OnClickListener() { 17 @Override 18 public void onClick(View view) { 19 textview.setText(editText.getText().toString()); 20 String string = editText.getText().toString(); 21 22 Log.d("EditTextTest",string); 23 } 24 }; 25 26 @Override 27 protected void onCreate(Bundle savedInstanceState) { 28 super.onCreate(savedInstanceState); 29 setContentView(R.layout.activity_main); 30 31 textview = findViewById(R.id.textview); 32 editText = findViewById(R.id.edittext); 33 button = findViewById(R.id.button); 34 button.setOnClickListener(buttonListener); 35 } 36} 37

main XML

XML

1<?xml version="1.0" encoding="utf-8"?> 2<RelativeLayout 3 xmlns:android="http://schemas.android.com/apk/res/android" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent"> 7 <!--android:paddingBottom="@dimen/activity_vertical_margin"--> 8 <!--android:paddingLeft="@dimen/activity_horizontal_margin"--> 9 <!--android:paddingRight="@dimen/activity_horizontal_margin"--> 10 <!--android:paddingTop="@dimen/activity_vertical_margin"--> 11 <!--tools:context=".MainActivity">--> 12 13 <TextView 14 android:id="@+id/textview" 15 android:layout_width="wrap_content" 16 android:layout_height="wrap_content" 17 android:text="Hello World!"/> 18 19 <EditText 20 android:id="@+id/edittext" 21 android:layout_width="match_parent" 22 android:layout_height="wrap_content" 23 android:layout_below="@+id/textview"/> 24 25 26 <Button 27 android:id="@+id/button" 28 android:layout_width="match_parent" 29 android:layout_height="wrap_content" 30 android:layout_below="@+id/edittext" 31 android:text="button"/> 32 33</RelativeLayout>

エミュレータの画像ですテンキーを表示させたい

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

参考にしたサイトには

xml

1 <include 2 layout="@layout/ten_key" 3 android:layout_width="match_parent" 4 android:layout_height="wrap_content" 5 android:layout_below="@id/button" 6 />

という記述がありますが、ご提示いただいた「main XML」にはこれが見当たりません。このincludeとは別ファイルに記述した内容を埋め込むという意味があって、テンキーのために記述したten_key.xmlをここに埋め込むことでテンキーを表示させているものと思われます。この記述がないので、ten_key.xmlの内容を表示する場所が存在しない状態なのでしょう。

投稿2018/09/02 05:12

keicha_hrs

総合スコア6766

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

gomakasu423

2018/09/02 05:24

ありがとうございます! 忘れていました、追記してみます
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問