Tengo este error:
Second_Fragment cannot be converted to Fragment
Código:
public class Second_fragment extends Fragment {
String direccion_web = "https://www.google.es/";
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.second_tab,container,false);
WebView appWeb = (WebView) getActivity().findViewById(R.id.webView);
//Habilitamos el javaScript y el zoom
appWeb.getSettings().setJavaScriptEnabled(true);
appWeb.getSettings().setBuiltInZoomControls(true);
//Cargamos el enlace definido
appWeb.loadUrl(direccion_web);
//Este método es para que el navegador se quede en nuestra aplicación
appWeb.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
return v;
}
second_tab.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="304dp" />
</LinearLayout>
¿Qué es lo que falla? ¿No se puede implementar esto en un Fragment?
public class MainActivity extends AppCompatActivity {
BottomBar mBottomBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mBottomBar = BottomBar.attach(this, savedInstanceState);
mBottomBar.setItemsFromMenu(R.menu.menu_main, new OnMenuTabSelectedListener() {
@Override
public void onMenuItemSelected(@IdRes int i) {
if (i == R.id.one) {
First_fragment f1 = new First_fragment();
getSupportFragmentManager().beginTransaction().replace(R.id.frame,f1).commit();
}
if (i == R.id.two) {
Second_fragment f2 = new Second_fragment();
getSupportFragmentManager().beginTransaction().replace(R.id.frame, f2).commit();
}
if (i == R.id.three) {
Three_fragment f3 = new Three_fragment();
getSupportFragmentManager().beginTransaction().replace(R.id.frame, f3).commit();
}
if (i == R.id.four) {
Four_fragment f4 = new Four_fragment();
getSupportFragmentManager().beginTransaction().replace(R.id.frame, f4).commit();
}
if (i == R.id.five) {
Five_fragment f5 = new Five_fragment();
getSupportFragmentManager().beginTransaction().replace(R.id.frame, f5).commit();
}
}
});
mBottomBar.mapColorForTab(0, "#c92029");
mBottomBar.mapColorForTab(1, "#c92029");
mBottomBar.mapColorForTab(2, "#c92029");
mBottomBar.mapColorForTab(3, "#c92029");
mBottomBar.mapColorForTab(4, "#c92029");
}
}
import android.support.v4.app.Fragment
WebView appWeb = (WebView) v.findViewById(R.id.webView);
y has intentado extender deFragmentActivity
?