自定义导航抽屉与活动?

时间:2014-06-16 16:11:24

标签: android

我有以下模板用于在活动中制作自定义列表视图。

如何使用此模板设置Android内listviews元素内的navigationDrawer

是否可以通过活动来宣传navigationDrawer

public class MainActivity extends ListActivity {

Context context;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mainlist);

    context = this;

    CheckboxListAdapter adapter = new CheckboxListAdapter(getLayoutInflater());
    this.getListView().setAdapter(adapter);

    this.getListView().setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {

                if(position == 0)
                {   


                }                   


            };
        });

}

 public class CheckboxListAdapter extends BaseAdapter implements OnClickListener {

    private LayoutInflater inflator;

    public CheckboxListAdapter(LayoutInflater inflator) {
        super();
        this.inflator = inflator;

    }

    public void onClick(DialogInterface dialog, int which) {

    }

    public View getView(int position, View view, ViewGroup parent) {

        if(position == 0)
        {

        }else if(position == 1)
        {                   

        }
        else if(position == 2)
        {

        }


        return view;
    }

    public int getCount() {

        return 3;
    }

    public Object getItem(int position) {

        return null;
    }
    public long getItemId(int position) {

        return position;
    }

}

}

1 个答案:

答案 0 :(得分:0)

检查此链接。 http://developer.android.com/training/implementing-navigation/nav-drawer.html 它使用ListView作为抽屉。

基本上,您需要执行以下操作

  1. 扩展Activity而不是ListActivity.
  2. DrawerLayout应该是布局的根视图。

    &lt; android.support.v4.widget.DrawerLayout xmlns:android =“http://schemas.android.com/apk/res/android”&gt;     &lt; ListView android:id =“@ + id / my_drawer”     ... /&gt;
    &LT; /android.support.v4.widget.DrawerLayout>

  3. 因此,请参考抽屉中的this.getListView()替换ListView