你难道没有用eclipse之类的工具呢?
应该是如下这样子的。
myButton.setOnClickListener(new OnClickListener(){   public void onClick(View v){
.......
}); 

解决方案 »

  1.   

    1.建议一种方式,在button的xml文件中设置android:onclick="自己定义个方法,如:mBtnListener"
    2.在Activity中 写上自己定义的方法 ,如public void mBtnListener(View v){  
    switch (v.getId){
    case R.id.button的id :
    //处理点击事件
    break;
    }
     }
    3.看了下面这段代码,这可是个fragment,如果是fragment的话,必须find到这个button的id,并且setonlickListener(),button才有效
    if (savedInstanceState == null) {
    getSupportFragmentManager().beginTransaction()
    .add(R.id.container, new PlaceholderFragment()).commit();
    }
      

  2.   


    这个在R.id中 找到myButton
      

  3.   


    这个在R.id中 找到myButton你调试试试,看是不是执行到这步时,myButton的值是什么
      

  4.   

    是build不过吗?
    myButton.setOnClickListener(new ButtonListener()); 
    把new ButtonListener()改成(View.OnClickListener)(new ButtonListener())
    不过一般情况下是按1楼的写法写button响应时间的
      

  5.   

    你还是看看你的控件是否放在 activity_main里面的吧。
      

  6.   

    你的绑定监听器不对吧,要么就直接在里面弄个类部类的形式,myButton.setOnClickListener(new ButtonListener(){});要么就直接生成一个ButtonListener对象替换掉这句myButton.setOnClickListener(new ButtonListener())中的new ButtonListener();
      

  7.   

    楼主有if (savedInstanceState == null) {
    getSupportFragmentManager().beginTransaction()
    .add(R.id.container, new PlaceholderFragment()).commit();
    }
    }这段代码,项目中是不是下面有Fragment.xml
    如果有的话,请参照下面http://blog.csdn.net/u013671350/article/details/37742673.
    希望帮助到你
      

  8.   


    是有Fragment_main.xml,但是把控件初始化在public static class PlaceholderFragment extends Fragment {  }这个里面会报错,提示findViewById报错,去掉static不会报错但是绑定的监听器依旧无法运行。方便的话qq交流方便。1258716539
      

  9.   


    是有Fragment_main.xml,但是把控件初始化在public static class PlaceholderFragment extends Fragment {  }这个里面会报错,提示findViewById报错,去掉static不会报错但是绑定的监听器依旧无法运行。方便的话qq交流方便。1258716539
    是有Fragment_main.xml,但是把控件初始化在public static class PlaceholderFragment extends Fragment {  }这个里面会报错,提示findViewById报错,
    去掉static不会报错但是绑定的监听器依旧无法运行。方便的话qq交流方便。1258716539
      

  10.   


    是有Fragment_main.xml,但是把控件初始化在public static class PlaceholderFragment extends Fragment {  }这个里面会报错,提示findViewById报错,去掉static不会报错但是绑定的监听器依旧无法运行。方便的话qq交流方便。1258716539
    是有Fragment_main.xml,但是把控件初始化在public static class PlaceholderFragment extends Fragment {  }这个里面会报错,提示findViewById报错,
    去掉static不会报错但是绑定的监听器依旧无法运行。方便的话qq交流方便。1258716539首先你可以按照我blog里的去掉fragment.xml,然后在加按钮应该没问题,其次你想在分布局fragment.xml加按钮有对应的语法,你直接写肯定不对的
      

  11.   


    首先你可以按照我blog里的去掉fragment.xml,然后在加按钮应该没问题,其次你想在分布局fragment.xml加按钮有对应的语法,你直接写肯定不对的fragment.xml里面是添加了button按钮的<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="10px"
    tools:context="com.example.hiworld.MainActivity$PlaceholderFragment"
    >

        <TextView
            android:id="@+id/label"
            android:text="test"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            />
        
        <EditText 
            android:id="@+id/edittext"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/label"
            android:background="#00aaaa"
            />
        
        <Button 
            android:id="@+id/ok"
            android:text="ok"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/edittext"
            android:layout_alignParentRight="true" 
            android:layout_marginLeft="20px"
            />
        
        <Button 
            android:id="@+id/cancel"
            android:text="cancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/edittext"  
            android:layout_toLeftOf="@+id/ok"    
            android:layout_alignLeft="@+id/edittext"
            />
    </RelativeLayout>然后在Fragment 里面初始化button就报错
    public static class PlaceholderFragment extends Fragment { public PlaceholderFragment() {
    } @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main, container,
    false);

    Button mybutton = (Button)findViewById(R.id.cancel); findViewById报错Cannot make a static reference to the non-static method findViewById(int) from the type Activity
    mybutton.setText("我的第一个button");

    return rootView;
    }
    }
      

  12.   

    public  class PlaceholderFragment extends Fragment {public PlaceholderFragment() {
    }@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main, container,
    false);Button mybutton = (Button)rootView.findViewById(R.id.cancel);
    mybutton.setText("我的第一个button");return rootView;
    }
    }楼主,你应该回炉重学一下java...
      

  13.   

    改了第一行的类声明和findViewById那行。
      

  14.   


    首先你可以按照我blog里的去掉fragment.xml,然后在加按钮应该没问题,其次你想在分布局fragment.xml加按钮有对应的语法,你直接写肯定不对的fragment.xml里面是添加了button按钮的<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="10px"
    tools:context="com.example.hiworld.MainActivity$PlaceholderFragment"
    >

        <TextView
            android:id="@+id/label"
            android:text="test"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            />
        
        <EditText 
            android:id="@+id/edittext"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/label"
            android:background="#00aaaa"
            />
        
        <Button 
            android:id="@+id/ok"
            android:text="ok"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/edittext"
            android:layout_alignParentRight="true" 
            android:layout_marginLeft="20px"
            />
        
        <Button 
            android:id="@+id/cancel"
            android:text="cancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/edittext"  
            android:layout_toLeftOf="@+id/ok"    
            android:layout_alignLeft="@+id/edittext"
            />
    </RelativeLayout>然后在Fragment 里面初始化button就报错
    public static class PlaceholderFragment extends Fragment { public PlaceholderFragment() {
    } @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main, container,
    false);

    Button mybutton = (Button)findViewById(R.id.cancel); findViewById报错Cannot make a static reference to the non-static method findViewById(int) from the type Activity
    mybutton.setText("我的第一个button");

    return rootView;
    }
    }
    不建议新手用fragment.xml很多知识点,楼主看视频什么的,别人的代码还是用第一种办法