0

Androidプログラミングは初めてで、誰かが私を助けてくれることを願っています: 1.私はここのデモの1つからコーディングしています: http://developer.android.com/training/animation/screen-slide.html

  1. メインの activity_screen_slide.xml ファイルがあります。

    <android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent"> </android.support.v4.view.ViewPager>

  2. 別の xml ファイル main.xml には、いくつかのボタンがあります。

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/Main" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <Button android:id="@+id/buttonStart" android:text="test"/> </LinearLayout>

メインの Java アクティビティ ファイル内で、コンテキストは次のように設定されます。

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_screen_slide);

testButton のリスナーを設定しようとすると、設定できません。これは、その後 (別の Java ファイルのインフレータを介して) ボタンが生成されたときに、ボタンをクリックしても応答がないことを意味します。

インフレータを生成する Java ファイルは次のとおりです。

ViewGroup rootView;
rootView = (ViewGroup) inflater.inflate(R.layout.main, container, false);

ありがとう、あなたの助けに感謝します

乾杯D

4

2 に答える 2

0

あなたのボタンは、xml レイアウトのactivity_screen_slide.xmlで次のように定義されていると思います。

<Button
    android:id="@+id/myButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />

アクティビティでは、次のように ClickListener を追加できます。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button myButton = (Button) findViewById(R.id.myButton);
    myButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Log.i("", "I've been clicked");
        }
    });
}
于 2013-08-11T16:36:36.947 に答える
0

これを試して:

public class Settings extends Activity implements View.OnClickListener {


    public void onCreate(Bundle savedInstanceState) {
        //...ALL THE OTHER CODE..\\
        Button button = (Button) findViewById(R.id.YOUR_BUTTON_ID);
        button.setOnClickListener(this);
    }
     @Override
public void onClick(View view) {
    switch (view.getId()){
        case R.id.YOUR_BUTTON_ID: {

            ALPHA.YourFunction(parameters);

        }
    }
}
}
于 2013-08-11T16:36:56.897 に答える