Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 创建乘法表布局_Android - Fatal编程技术网

Android 创建乘法表布局

Android 创建乘法表布局,android,Android,我试图生成用户输入的任意数字的乘法表。我已经为应用程序开发了接口,但无法理解从何处开始使用逻辑部分(编码)。我想要的是,当用户在EditText中输入一个数字时,在TextView(id:printArea)中,应该以如图2所示的格式显示输入数字的表格。[为了向您展示示例,我在printArea部分中使用了TextView,但我不知道该使用什么来代替它] <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:and

我试图生成用户输入的任意数字的乘法表。我已经为应用程序开发了接口,但无法理解从何处开始使用逻辑部分(编码)。我想要的是,当用户在EditText中输入一个数字时,在TextView(id:printArea)中,应该以如图2所示的格式显示输入数字的表格。[为了向您展示示例,我在printArea部分中使用了TextView,但我不知道该使用什么来代替它]

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
    tools:context=".MainActivity"
    android:weightSum="1">

    <LinearLayout

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16dp"
            android:text="Please Enter a Number: "
            android:textSize="20sp" />

        <EditText
            android:id="@+id/num"
            android:layout_width="90dp"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_marginLeft="30dp"
            android:textSize="20sp" />

    </LinearLayout>


    <Button
        android:id="@+id/calculate"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/log"
        android:onClick="submitNumber"
        android:text="Get Table" />

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1.0"
    android:id="@+id/printArea" />

    <LinearLayout

        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <Button
            android:id="@+id/clear"
            android:layout_width="125dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="2dp"
            android:layout_marginRight="1dp"
            android:text="Clear" />

        <Button
            android:id="@+id/credits"
            android:layout_width="125dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="1dp"
            android:layout_marginRight="1dp"
            android:text="Credits" />

        <Button
            android:id="@+id/exit"
            android:layout_width="125dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="1dp"
            android:layout_marginRight="2dp"
            android:text="Exit" />

    </LinearLayout>

</LinearLayout>

MainActivity.java是:

package com.example.tara.multiplicationtable;
导入android.content.Intent;
导入android.support.v7.app.AppActivity;
导入android.os.Bundle;
导入android.view.view;
导入android.widget.Button;
导入android.widget.EditText;
导入android.widget.TextView;
公共类MainActivity扩展了AppCompatActivity{
编辑文本数;
按钮积分;
按钮计算;
按钮清晰;
按钮出口;
文本视图打印区;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
num=新编辑文本(此);
清除=新按钮(此按钮);
计算=新按钮(此按钮);
信用=新按钮(此按钮);
计算=新按钮(此按钮);
printArea=新文本视图(此);
num=(EditText)findViewById(R.id.num);
积分=(按钮)findViewById(R.id.credits);
清除=(按钮)findViewById(R.id.clear);
退出=(按钮)findViewById(R.id.exit);
printArea=(TextView)findViewById(R.id.printArea);
calculate=(按钮)findViewById(R.id.calculate);
calculate.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
//将整数值更改为字符串
int num1=Integer.parseInt(num.getText().toString());
//单击后执行操作

对于(inti=1;i创建一个Listview,然后在其适配器中添加表数据。 使适配器的布局如下所示:

 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="2"            />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="*" />
   <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="2" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="=" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="4" />


以下是我用来构建我设想构建的乘法表的代码。activity\u main.xml文件的代码如下:


MainActivity.java文件的代码为:

package com.example.tara.multiplicationtable;
导入android.content.Intent;
导入android.support.v7.app.AppActivity;
导入android.os.Bundle;
导入android.view.view;
导入android.view.WindowManager;
导入android.widget.Button;
导入android.widget.EditText;
导入android.widget.TextView;
导入android.widget.Toast;
公共类MainActivity扩展了AppCompatActivity{
编辑文本数;
按钮积分;
按钮计算;
按钮清晰;
按钮出口;
文本视图打印区;
//私有静态最终字符串结果=MainActivity.class.getSimpleName();
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
num=新编辑文本(此);
清除=新按钮(此按钮);
计算=新按钮(此按钮);
信用=新按钮(此按钮);
计算=新按钮(此按钮);
printArea=新文本视图(此);
num=(EditText)findViewById(R.id.num);
积分=(按钮)findViewById(R.id.credits);
清除=(按钮)findViewById(R.id.clear);
退出=(按钮)findViewById(R.id.exit);
calculate=(按钮)findViewById(R.id.calculate);
printArea=(TextView)findViewById(R.id.printArea);
calculate.setOnClickListener(新视图.OnClickListener(){
//单击“获取表格”按钮执行操作
公共void onClick(视图v){
if(num.getText().length()==0){
printArea.setText(R.string.err_msg);
}
否则{
//将整数值更改为字符串
printArea.setText(“”);
int num1=Integer.parseInt(num.getText().toString());
字符串结果;

for(int i=1;i)在常规Java中如何执行相同的操作?在for循环中打印表格?在Android中也可以执行相同的操作。只需将内容写入TextView而不是System.out,然后单击EditText按钮即可从中获取输入