-3

Hi I'm new to Android development and I have to create a navigation drawer with different items on it.

The first row should contain a

Button

. The next three rows should contain

TexViews

, and the last row should contain an

EditText

I'm gone as far as creating the layout but I haven't the idea of how to call that inside the adapter.

YetAnotherBot
  • 1,937
  • 2
  • 25
  • 32
freeloader
  • 336
  • 2
  • 6
  • 18

2 Answers2

1

The Navigation Drawer isn't limited to a ListView. Maybe this is the reason why you want to choose one. You can use any View / ViewGroup to build your Drawer. Try a LinearLayout with some child Views of your choice. Something like this:

<LinearLayout
    android:id="@+id/drawer_view"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_gravity="start">

    <Button
        .../>
    <TextView
        .../>

</LinearLayout>

It's just an example, to show that you don't have to stick to a ListView as your Drawer.

Steve Benett
  • 12,843
  • 7
  • 59
  • 79
0

In getView, you need to check what type the item from getItem(position) is and inflate the proper layout based on that.

@Override
public View getView(int position, View convertView, ViewGroup parent)
{
    NavDrawerItem item = getItem(position);
    if (item.getType() == BUTTON_ITEM_TYPE)
    {
        convertView = inflater.inflate(R.layout.navdrawer_button, parent, false);
        //get references to individual views, etc.
    }
}

with an item interface like

public interface NavDrawerItem
{
    public static final int BUTTON_ITEM_TYPE = 1;
    public static final int TEXTVIEW_ITEM_TYPE = 2;

    public int getId();

    public String getLabel();

    public int getType();
}
ashishduh
  • 6,629
  • 3
  • 30
  • 35