我已经环顾四周并实现了一些我发现的东西,以便让findVIEwByID在我的Fragment中工作.但是,我得到了无法解析的方法findVIEwByID或者我得到了“无法访问的语句”.我不完全确定我哪里出错了.
这是我的片段的代码.
import androID.app.Fragment;import androID.os.Bundle;import androID.support.annotation.Nullable;import androID.vIEw.LayoutInflater;import androID.vIEw.VIEw;import androID.vIEw.VIEwGroup;import androID.Widget.RadioGroup;/** * Created by James Singleton on 8/8/2016. */public class SettingsFragment extends Fragment{ VIEw myVIEw; @Nullable @OverrIDe public VIEw onCreateVIEw(LayoutInflater inflater, VIEwGroup container, Bundle savedInstanceState) { myVIEw = inflater.inflate(R.layout.settings_layout, container, false); return myVIEw; RadioGroup radioGroup = (RadioGroup) getVIEw().findVIEwByID(R.ID.radioGroup); radioGroup.setonCheckedchangelistener(new RadioGroup.OnCheckedchangelistener() { public voID onCheckedChanged(RadioGroup group, int checkedID) { // checkedID is the Radiobutton selected switch(checkedID) { case R.ID.radiobutton7: // switch to fragment 1 break; case R.ID.radiobutton6: // Fragment 2 break; } } }); }}
这是我的布局代码
<?xml version="1.0" enCoding="utf-8"?>
<TextVIEw androID:text="Use Cell Data to retrIEve driving data:" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:ID="@+ID/textVIEw" androID:textSize="18sp" androID:textcolor="@color/cast_expanded_controller_background_color" androID:layout_alignParenttop="true" androID:layout_alignParentStart="true" /><RadioGroup androID:layout_wIDth="89dp" androID:layout_height="69dp" androID:weightSum="1" androID:layout_below="@+ID/textVIEw" androID:ID="@+ID/radioGroup"> <Radiobutton androID:text="Enable" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:ID="@+ID/radiobutton7" androID:layout_weight="1" /> <Radiobutton androID:text="disable" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:ID="@+ID/radiobutton6" androID:layout_weight="1" androID:checked="true" /></RadioGroup>
解决方法:
像这样更改你的代码:
@Nullable @OverrIDe public VIEw onCreateVIEw(LayoutInflater inflater, VIEwGroup container, Bundle savedInstanceState) { myVIEw = inflater.inflate(R.layout.settings_layout, container, false); RadioGroup radioGroup = (RadioGroup) myVIEw .findVIEwByID(R.ID.radioGroup); radioGroup.setonCheckedchangelistener(new RadioGroup.OnCheckedchangelistener() { public voID onCheckedChanged(RadioGroup group, int checkedID) { // checkedID is the Radiobutton selected switch(checkedID) { case R.ID.radiobutton7: // switch to fragment 1 break; case R.ID.radiobutton6: // Fragment 2 break; } } }); return myVIEw; }
总结 以上是内存溢出为你收集整理的android – 单片机中的单选按钮findViewById全部内容,希望文章能够帮你解决android – 单片机中的单选按钮findViewById所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)