Hi guys, I am pretty new here and with android development. I have created my first app and am looking to expand on it and add some more style to it. What I am trying to do is add a navigation drawer to the app. So instead of the buttons on my home screen to bring me to new activities I want to have these buttons as selections in the drawer. But i have spent all day looking up tutorials and trying stuff out but I have made zero progress. Can anyone help start me off in the right track with my code?

So this is the main activity where i have my three buttons that I want to put into the drawer

package com.example.rory.dripdrop;    
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;


public class MyActivity extends Activity implements MyAdapterInterface{

    private CustomCursorAdapter customAdapter;
    public ListView list1;

    //instantiating the database class
    com.example.rory.dripdrop.DBAdapter db = new com.example.rory.dripdrop.DBAdapter(this);
    public MyActivity mMyActivity;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);

        list1 = (ListView)findViewById(R.id.data_list);
        db.open();

        mMyActivity = this;

        //button and listener for add activity
        Button addBtn = (Button)findViewById(R.id.add);
        addBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent i = new Intent(MyActivity.this, Add.class);
                startActivity(i);
            }
        });

        //button and listener for delete activity
        Button deleteBtn = (Button)findViewById(R.id.delete);
        deleteBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent i = new Intent(MyActivity.this, Delete.class);
                startActivity(i);
            }
        });

        //button and listener for update activity
        Button updateBtn = (Button)findViewById(R.id.update);
        updateBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent i = new Intent(MyActivity.this, Update.class);
                startActivity(i);
            }
        });


        try {
            String destPath = "/data/data/" + getPackageName() + "/databases/AssignmentDB";
            File f = new File(destPath);
            if (!f.exists()) {
                CopyDB( getBaseContext().getAssets().open("mydb"),
                        new FileOutputStream(destPath));
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


        //handler function for custom adapter, found example online to help with this
        new Handler().post(new Runnable() {
            @Override
            public void run() {
                customAdapter = new CustomCursorAdapter(MyActivity.this, db.getAllRecords(), mMyActivity);
                list1.setAdapter(customAdapter);
            }
        });

    }

    public void onResume()
    {
        super.onResume();
        //update list
        addData();
    }

    //refreshes data base when main page is resumed
    public void addData()
    {

        //handler function for custom adapter, found example online to help with this
        new Handler().post(new Runnable() {
            @Override
            public void run() {
                customAdapter = new CustomCursorAdapter(MyActivity.this, db.getAllRecords(), mMyActivity);
                list1.setAdapter(customAdapter);
            }
        });

    }


    //chaning the running total
    public void updateLitres(int value)
    {
        EditText editLitres = (EditText)findViewById(R.id.edit1);
        //EditText myEditText2 = (EditText)findViewById(R.id.edit2);

        editLitres.setText(String.valueOf(value));
        //myEditText2.setText(String.valueOf(value));
    }

    public void updateCost(double value)
    {
        EditText editCost = (EditText)findViewById(R.id.edit2);
        editCost.setText(String.valueOf(value));
    }

    private class DBAdapter extends BaseAdapter {
        private LayoutInflater mInflater;
        //private ArrayList<>

        @Override
        public int getCount() {

            return 0;
        }

        @Override
        public Object getItem(int arg0) {

            return null;
        }

        @Override
        public long getItemId(int arg0) {

            return 0;
        }

        @Override
        public View getView(int arg0, View arg1, ViewGroup arg2) {

            return null;
        }

    }

    public void CopyDB(InputStream inputStream, OutputStream outputStream)
            throws IOException {
        //---copy 1K bytes at a time---
        byte[] buffer = new byte[1024];
        int length;
        while ((length = inputStream.read(buffer)) > 0) {
            outputStream.write(buffer, 0, length);
        }
        inputStream.close();
        outputStream.close();
    }
}

And this is the XML of that Activity

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:padding="20dp"
    android:background="@drawable/backg1">

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="fill_parent"
        android:layout_height="331dp"
        android:layout_weight="0.44"
        android:fillViewport="true" >

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <ListView
                android:id="@+id/data_list"
                android:textStyle="bold"
                android:layout_width="fill_parent"
                android:layout_height="355dp">
            </ListView>
        </LinearLayout>
    </ScrollView>


    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/total"
            android:text="@string/total"
            android:textStyle="bold"
            android:textColor="@color/black"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <EditText
            android:id="@+id/edit1"
            android:layout_toRightOf="@+id/total"
            android:layout_width="75dp"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/totalCost"
            android:text="@string/total2"
            android:textStyle="bold"
            android:textColor="@color/black"
            android:layout_toRightOf="@+id/edit1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <EditText
            android:id="@+id/edit2"
            android:layout_toRightOf="@+id/totalCost"
            android:layout_width="75dp"
            android:layout_height="wrap_content" />

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="1">


        <Button
            android:id="@+id/add"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:text="@string/add"
            android:textStyle="bold"
            android:layout_centerVertical="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />

        <Button
            android:id="@+id/delete"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/delete"
            android:textStyle="bold"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true" />

        <Button
            android:id="@+id/update"
            android:layout_gravity="right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/update"
            android:textStyle="bold"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />

    </RelativeLayout>

</LinearLayout>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.