0

これはボタンクリックで発生します

私のActivity.XMLファイル

<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">

<EditText android:id="@+id/enter_number"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:hint="@string/enter_number"
    android:layout_weight="1"
    />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_calculate" 
    android:onClick="calculate"
    />
</LinearLayout>

.java ファイル

    package com.example.helloworld;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.widget.TextView;

public class Tables extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Get the message from the intent
        int number=0;
        int i=1;
        int next=0;
        Intent intent = getIntent();
        String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
        number=Integer.parseInt(message);
        TextView textView = new TextView(this);

        String[] myString = new String[10]; //create array
        for (i = 1; i <= myString.length; i++) { 
             next= number + next;
             myString[i] =  String.valueOf(number)+'x'+String.valueOf(i)+'='+String.valueOf(next)+'\n';
            // textView.setText(myString[i]);  
            // setContentView(textView);
        }
        StringBuilder builder = new StringBuilder();
        for (String s : myString){
          builder.append(s+" ");
        textView.setText(builder.toString());
        }
        setContentView(textView);

    }



    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_tables, menu);
        return true;
    }
}

エラーは表示中だと思います。しかし、解決策が見つかりません。

ありがとう、

4

2 に答える 2

1

calculateアクティビティでメソッドを定義する必要があります。レイアウトファイルでプロパティを設定したのでonClick、ボタンをクリックすると、AndroidフレームワークはTablesアクティビティのfollowメソッドを呼び出そうとします。

  public void calculate(View v){
      //put you code here this will be execute when the button is clicked
  }
于 2012-08-24T02:58:00.133 に答える
0

レイアウト ファイルはアクティビティ用ではなく、メイン アクティビティ用のようTablesです。アクティビティがボタンのクリックに応答できるように、MainActivityクラスに署名付きのメソッドがあることを確認してください。アクティビティpublic void calculate(View view)の表示の問題ではなく、これが問題である可能性があります。Tables

于 2012-08-24T04:31:31.973 に答える