Task : I have created a fragment drawer where i have i have textview with text "myname" just below my image and then there is nav_row item so what i want to do is when this text is clicked it should switch activity from MainActivity to profileinfo and i have webview created and its activity profileinfo that should load my html file...So what i did is here-->
this is my activity_main xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
</LinearLayout>
<FrameLayout
android:id="@+id/container_body"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<webview xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/aboutYou"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
</webview>
</LinearLayout>
<fragment
android:id="@+id/fragment_navigation_drawer"
android:name="com.medmainfomatix.mdesign.FragmentDrawer"
android:layout_width="@dimen/nav_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="@layout/fragment_navigation_drawer"
tools:layout="@layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
webview xml is here -->
<?xml version="1.0" encoding="utf-8"?>
<webview xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/aboutYou"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
</webview>
profileinfo activity
public class profileinfo extends AppCompatActivity{
private WebView aboutYou;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
aboutYou = (WebView) findViewById(R.id.aboutYou);
aboutYou.loadUrl("file:///android_assets/profile_info.html");
}
}
This is my MainActivity class
public class MainActivity extends AppCompatActivity implements FragmentDrawer.FragmentDrawerListener {
private static String TAG = MainActivity.class.getSimpleName();
TextView pname;
private Toolbar mToolbar;
private FragmentDrawer drawerFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
drawerFragment = (FragmentDrawer)
getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar);
drawerFragment.setDrawerListener(this);
displayView(0);
pname = (TextView) findViewById(R.id.pname);
pname.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent inent = new Intent(MainActivity.this,profileinfo.class);
startActivity(inent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
Toast.makeText(getApplicationContext(), "Search action is selected!", Toast.LENGTH_SHORT).show();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onDrawerItemSelected(View view, int position) {
displayView(position);
}
private void displayView(int position) {
Fragment fragment = null;
String title = getString(R.string.app_name);
switch (position) {
case 0:
fragment = new HomeFragment();
title = getString(R.string.title_home);
break;
case 1:
fragment = new FriendsFragment();
title = getString(R.string.title_friends);
break;
case 2:
fragment = new MessagesFragment();
title = getString(R.string.title_messages);
break;
default:
break;
}
if (fragment != null) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.container_body, fragment);
fragmentTransaction.commit();
// set the toolbar title
getSupportActionBar().setTitle(title);
}
}
}
Here is my textview info in this xml fragment navigation drawer
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">
<RelativeLayout
android:id="@+id/nav_header_container"
android:layout_width="match_parent"
android:layout_height="140dp"
android:layout_alignParentTop="true"
android:background="@color/colorPrimary">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:src="@drawable/profile"
android:scaleType="fitCenter"
android:layout_centerInParent="true" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/drawerList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/nav_header_container"
android:layout_marginTop="15dp" />
<TextView
android:id="@+id/pname"
android:textStyle="bold"
android:layout_marginTop="110dp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/profile_name"
android:clickable="true"
android:onClick="onClick"/>
</RelativeLayout>
Don't worry about other class and xml please take a look and where i am wrong.
I am getting this --> AndroidRuntime: FATAL EXCEPTION: main Process: com.medmainfomatix.mdesign, PID: 27497 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.medmainfomatix.mdesign/com.medmainfomatix.mdesign.profileinfo}: android.view.InflateException: Binary XML file line #2: Error inflating class webview at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2455) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2519) at android.app.ActivityThread.access$800(ActivityThread.java:162) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:189) at android.app.ActivityThread.main(ActivityThread.java:5532) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745) Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class webview at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:757) at android.view.LayoutInflater.inflate(LayoutInflater.java:482) at android.view.LayoutInflater.inflate(LayoutInflater.java:414) at android.view.LayoutInflater.inflate(LayoutInflater.java:365) at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) at com.medmainfomatix.mdesign.profileinfo.onCreate(profileinfo.java:16) at android.app.Activity.performCreate(Activity.java:5966) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2408) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2519) at android.app.ActivityThread.access$800(ActivityThread.java:162) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:189) at android.app.ActivityThread.main(ActivityThread.java:5532) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745) Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.webview" on path: DexPathList[[zip file "/data/app/com.medmainfomatix.mdesign-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:511) at java.lang.ClassLoader.loadClass(ClassLoader.java:469) at android.view.LayoutInflater.createView(LayoutInflater.java:571) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:665) at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:65) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741) at android.view.LayoutInflater.inflate(LayoutInflater.java:482) at android.view.LayoutInflater.inflate(LayoutInflater.java:414) at android.view.LayoutInflater.inflate(LayoutInflater.java:365) at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) at com.medmainfomatix.mdesign.profileinfo.onCreate(profileinfo.java:16) at android.app.Activity.performCreate(Activity.java:5966) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2408) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2519) at android.app.ActivityThread.access$800(ActivityThread.java:162) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:189) at android.app.ActivityThread.main(ActivityThread.java:5532) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745) Suppressed: java.lang.ClassNotFoundException: Didn't find class "android.view.webview" on path: DexPathList[[dex file "/data/data/com.medmainfomatix.mdesign/files/instant-run/dex/slice-support-annotations-24.2.1_0a328bfef112abe9401e5ad651d5b475868a0fa2-classes.dex", dex file "/data/data/com.medmainfomatix.mdesign/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.medmainfomatix.mdesign/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.medmainfomatix.mdesign/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.medmainfomatix.mdesign/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.medmainfomatix.mdesign/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.medmainfomatix.mdesign/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.medmainfomatix.mdesign/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.medmainfomatix.mdesign/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.medmainfomatix.mdesign/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.medmainfomatix.mdesign/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/com.medmainfomatix.mdesign/files/instant-run/dex/slice-internal_impl-24.2.1_c5d6f1d87c5057b6eaca56a24d54d014044b8659-cla