0

ボタンであるリソースにアクセスしようとすると、プロジェクトがエラーをスローし始めることに突然気付きました。R.id.button に下線が引かれます。理由がわかりません。作成した最後のxmlも削除しましたが、問題は解決しません。

これは私のxmlファイルの例です

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/layoutborder"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/chat"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:text="@string/stepone"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@color/wine" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:src="@drawable/ai" />

    <Button
        android:id="@+id/drugdetails"
        style="@style/smallButtonStyleBlackpearl"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="10dp"
        android:text="@string/nextbut" />

</LinearLayout>

私のJavaコード

package com.example.rhemahealthcare;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.actionbarsherlock.app.SherlockActivity;
import com.example.rhemahealthcare.R;

public class SteponeActivity extends SherlockActivity{


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

        final Button button = (Button)findViewById(R.id.button1);
        button.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View v){
                // TODO Auto-generated method stub
                Intent intent = new Intent(SteponeActivity.this,SteptwoActivity.class);
                startActivity(intent);
            }

        });
    }

}
4

3 に答える 3

1

ボタン 1 の ID を変更するには、右クリックして [ID の編集] を選択します。このオプションは、すべてのレイアウトでその名前を持つすべての ID を変更します。

于 2013-09-23T19:39:19.283 に答える
0

@Aleks G がコメントで正しく説明したようbutton1に、xmlファイルのように id を持つボタンはありません。あなたはそれについて言及しました:

final Button button = (Button)findViewById(R.id.button1);

適切な ID を使用するか、レイアウト ファイルに入れます。

于 2013-09-23T16:07:51.077 に答える
0

私は問題を理解しました。私のボタンIDは自動的にbutton1に変更されたので、私が与えた以前のIDを参照しませんでした。どうもありがとう

于 2013-09-23T16:08:40.613 に答える