Adding a linear layout to Navigation drawer (ends up crashing with a ClassCastException)

后端 未结 5 1484
遇见更好的自我
遇见更好的自我 2020-12-10 07:06

I am trying to add a vertical linear layout (having a title, image, menu title, listview and an icon at the bottom)to the navigation drawer. However the app crashes displayi

5条回答
  •  猫巷女王i
    2020-12-10 07:43

    Your query is difficult to understand without code & stacktrace, but anyway..

    Remember android.support.v4.widget.DrawerLayout can have 3 elements only (in exactly this order):

    1. Your main page

    2. Left Drawer

    3. Right Drawer

    Copy paste this example(only first two elements are there) & continue with your requirements

    
    
    
    
    
    
        
    
            
    
        
    
        
    
    
    
    
    
    
        
    
        
    
        
    
    
    
    

    Your Activity:

    public class MainActivity extends Activity {
    RelativeLayout leftRL;
    RelativeLayout rightRL;
    DrawerLayout drawerLayout;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    //        I'm removing the ActionBar.
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.temp);
    
        leftRL = (RelativeLayout)findViewById(R.id.whatYouWantInLeftDrawer);
        drawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
        }
    
        public  void onOpenLeftDrawer(View view)
        {
        drawerLayout.openDrawer(leftRL);
        }
    }
    

提交回复
热议问题