我創建了一個FragmentOne extends Fragment
,我正在以下編譯時錯誤:不能轉換到碎片
"cannot be converted to Fragment!",
我下面這個tutorial
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void selectFrag(View view){
Fragment fragment;
if(view == findViewById(R.id.button1)){
fragment = new FragmentOne();
}
}
}
檢查進口。如果您使用支持片段的FragmentTransaction然後使用片段 –
的V4格式檢查是否[this](http://stackoverflow.com/questions/29656822/type-mismatch-cannot-convert-from-listfragment-to-fragment )幫助 – Blackbelt