-6

次のコードで私を助けてください... Android アプリケーションを作成しようとしていますが、onCreate 内で関数を作成しようとするとコードでエラーが発生します.. 関数を作成する必要があるのは、ボタン、ラベル、およびテキストボックス....ここに私のコードがあります

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final EditText player = (EditText)findViewById(R.id.player);
    final TextView plrlbl1 = (TextView)findViewById(R.id.textView1);
    final ImageButton imageButton1 = (ImageButton)findViewById(R.id.imageButton1);
    final ImageButton imageButton2 = (ImageButton)findViewById(R.id.imageButton2);

    public void thisfunction()
    {

    }
}

oncreate内に関数を作成するのを手伝ってください...助けてください

4

3 に答える 3

8
public void thisfunction()
    {

    }

thisfunction()の中で宣言しますonCreate()。の外で宣言する必要がありonCreateます。この種の問題を抱えている場合は、基本的なプログラミングの本を読むことをお勧めします。

于 2012-07-03T08:12:20.517 に答える
3

oncreate 内で関数を作成するのを手伝ってください...

できません。Java では許可されていません。の外で宣言する必要がありonCreate()ます。

于 2012-07-03T08:13:55.120 に答える
1

正しい設定はこのようなものです

public class MyActivity extended Activity {

private TextView myTextView;

    @Override 
    public void onCreate (Bundle savedInstanceState) {
        super.onCreate () ; 
        setContentView(R.layout.main) ; 

        myTextView = (TextView) findViewById (R.id.textView1) ; 

        myNewMethod() ; 
    }

    private void myNewMethod () {
        myTextView.setText("Hello world") ; 
    } 
} 
于 2012-07-04T06:07:15.057 に答える