如何将v4支持库添加到导航抽屉

时间:2015-05-16 06:42:08

标签: android

我是Android新手。我学习了Navigation Drawer示例,但我在lib文件夹中添加了支持库。

这是我的代码。在模拟器上运行时,ListView和导航抽屉没有区别:

// MainActivity 
public class MainActivity extends ActionBarActivity {
    private ListView listView;
    private DrawerLayout drawerLayout;
    private String[] MobilePhones = { "Nokia", "Sumsung", "MicroMax", "Nexus", "Asus" };;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        listView = (ListView) findViewById(R.id.listView);
        drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        listView.setAdapter(new ArrayAdapter<>(this,
                android.R.layout.simple_list_item_1, MobilePhones));
        listView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                // TODO Auto-generated method stub
                Toast.makeText(getApplicationContext(),
                        "Your selected Phone is " + MobilePhones[position],
                        Toast.LENGTH_SHORT).show();
            }
        });
    }
}

0 个答案:

没有答案