My Fragment.java
package make.appaplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class Fragment41 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_41);
TextView textViewDisplayResult = (TextView) findViewById(R.id.text_view_display_result);
textViewDisplayResult.setText(getIntent().getBooleanExtra("KEY_ANSWER", false)?R.string.Good_answer:R.string.Wrong_answer);
}
}
在MainActivity中
fragmentList.add(new Fragment41());
抛出add(android.support.v4.app.Fragment) in List can not be applied to (make.application.Fragment)
我添加了compile 'com.android.support:support-v4:25.1.1'
并重建,但一切都没有改变。
更新了Lalit用户的代码。 (我现在得到三种方法Can not resolve
并加下划线protected
)
package make.appaplication;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.widget.TextView;
public class Fragment41 extends android.support.v4.app.Fragment{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_41);
TextView textViewDisplayResult = (TextView) findViewById(R.id.text_view_display_result);
textViewDisplayResult.setText(getIntent().getBooleanExtra("KEY_ANSWER", false)?R.string.Good_answer:R.string.Wrong_answer);
}
}
答案 0 :(得分:0)
替换
中的代码public class MyFragment extends Fragment{
}
与
public class MyFragment extends android.support.v4.app.Fragment{
}
并更改导入
import android.app.Fragment;
到
import android.support.v4.app.Fragment;