RadioButton をクリックしてアクティビティからフラグメントに遷移すると、RadioButton を ViewGroup にキャストできないという classcastingexception が発生します。何か提案があれば、よろしくお願いします。
radioFeatures selected
11-20 12:50:08.794 4339-4339/com.example.justin.myapplication V/endofmain-features﹕ endofmain-features
11-20 12:50:08.802 4339-4339/com.example.justin.myapplication D/AndroidRuntime﹕ Shutting down VM
11-20 12:50:08.802 4339-4339/com.example.justin.myapplication W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40f2a930)
11-20 12:50:08.809 4339-4339/com.example.justin.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.ClassCastException: android.widget.RadioButton cannot be cast to android.view.ViewGroup
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:945)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:458)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
@Override
//protected void onCreate(Bundle savedInstanceState, ViewGroup container){
protected void onCreate(Bundle savedInstanceState) {
Log.v("Main.class", "Main.class");
super.onCreate(savedInstanceState);
setContentView(R.layout.button_tabs);
viewPager = (ViewPager) findViewById(R.id.pager);
mAdapter = new CustomButtonTabs(getSupportFragmentManager());
viewPager.setAdapter(mAdapter);
radioFeatures = (RadioButton) findViewById(R.id.radioFeatures);
radioFeatures.setOnClickListener(new View.OnClickListener() {
public void onClick(View vi) {
Log.v("radioFeatures selected", "radioFeatures selected");
FeaturesFragment frag = new FeaturesFragment();
android.support.v4.app.FragmentTransaction fragTransaction = getSupportFragmentManager().beginTransaction();
fragTransaction.replace(R.id.radioFeatures, frag);
fragTransaction.commit();
Log.v("endofmain-features", "endofmain-features");
}
});
to the following of FeaturesFragment:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log.v("FeaturesFragment", "FeaturesFragment");
// View v = (View) inflater.inflate(R.layout.carfeatures_list, container, false);
View v = inflater.inflate(R.layout.carfeatures_list, null);
ListView lv = (ListView) v.findViewById(android.R.id.list);
adapter = new CustomListViewAdapter(carFeaturesList, R.layout.carfeatures_list, super.getActivity());
lv.setAdapter(adapter);
v.findViewById(R.id.featureslist);
//Listview on item click listener
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//Gets values from selected ListItem
String car_features = ((TextView) view.findViewById(R.id.car_features)).getText().toString();
//Log.v("onCreate-car_features", car_features.toString());
String carfeatures_id = ((TextView) view.findViewById(R.id.carfeatures_id)).getText().toString();
//Log.v("onCreate-carfeatures_id", carfeatures_id.toString());
String model_id = ((TextView) view.findViewById(R.id.model_id)).getText().toString();
//Log.v("onCreate-model_id", model_id.toString());
String carfeatures_desc = ((TextView) view.findViewById(R.id.carfeatures_desc)).getText().toString();
//Log.v("onCreate-carfeats_desc", carfeatures_desc.toString());
Boolean b = Boolean.valueOf(TAG_CARID);
if (b == true) {
view.setBackgroundColor(Color.GREEN);
}
//Colors the selected listview item
if (previouslySelectedItem != null) {
previouslySelectedItem.setBackgroundColor(Color.TRANSPARENT);
Log.v("previouslySelectedItem", "!=null");
Log.v("position", Integer.toString(position));
}
view.setBackgroundColor(Color.GREEN);
Log.v("position", Integer.toString(position));
Log.v("outofif-view", view.toString());
previouslySelectedItem = view;
}
});
//Calls async task to get json
new GetCarFeatures().execute();
Log.v("return called-Features", "return called");
// Log.v("container-features", container.toString());
return v;
}