解决方案 »

  1.   

    .xml:
    <Button
                android:id="@+id/btnUpdate"
                android:layout_width="112dp"
                android:layout_height="wrap_content"
                android:text="Update"
                android:onClick="doUpdate" />.java:
        public void doUpdate(View v) {
         ...
        }
      

  2.   

    应该是引用布局中的的button控件
      

  3.   

    这几天刚遇到同样的功能,搜到你也遇到同样的问题,解决了,顺便把我解决的方法贴出来,应该对你有用。
    你是要在一个Preference里加载一个自定义布局,可以这样做:
    自己写一个类TextPreference,继承Preference,调用自定义布局文件如下:<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
        android:title="@string/storage_settings_title" >
        <PreferenceCategory
            android:key="phone_memory_category"
            android:title="@string/storage_settings_title" >    <com.android.settings.deviceinfo.TextPreference //自定义类
            android:fragment="com.android.settings.deviceinfo.Memory"
            android:key="phone_memory_ll"
            />
        </PreferenceCategory>
        </PreferenceScreen>在TextPreference类里面复写onCreateView方法,
    protected View onCreateView(ViewGroup parent) {
    // TODO Auto-generated method stub
    LayoutInflater inflater=(LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.phone_memory_linear_layout, null);
    mMaxTitle = (TextView)layout.findViewById(R.id.max_title);
    return layout;
    }
    然后你就可以欢快滴findViewById了。
    不是为了分,为了同样苦逼的IT民工吧。
      

  4.   


    Activity继承PreferenceActivity
    addPreferencesFromResource(R.xml.preference);//这句加载自定义的Preference文件
    Button btn=(Button) findPreference("btnKey");//这里就像findViewById一样,不过这里的id其实是key的值..这样就得到了xml中控件了,之后想怎么操作就怎么操作了!