package com.example.a10_drawerlayout_demo;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.widget.DrawerLayout;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends FragmentActivity {
private DrawerLayout drawerLayout;
private ListView listView;
private FrameLayout frameLayout;
private RelativeLayout relativeLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
//抽屉的跟布局
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
//选项的菜单
listView = (ListView) findViewById(R.id.list_view);
//主内容区域的布局
frameLayout = (FrameLayout) findViewById(R.id.frame_layout);
//抽屉显示的布局
relativeLayout = (RelativeLayout) findViewById(R.id.relative_layout);
final List<String> list = new ArrayList<>();
for (int i = 1; i<10;i++){
list.add(i+"");
}
//设置适配器
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_list_item_1, android.R.id.text1, list);
listView.setAdapter(arrayAdapter);
//条目的点击事件
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//要有一个fragment替换后面主内容的frameLayout
WeiXinFragment weiXinFragment = new WeiXinFragment();
//传值过去
Bundle bundle = new Bundle();
bundle.putString("key",list.get(i));
weiXinFragment.setArguments(bundle);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout,weiXinFragment).commit();
//关闭抽屉
drawerLayout.closeDrawer(relativeLayout);
}
});
}
}
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.widget.DrawerLayout;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends FragmentActivity {
private DrawerLayout drawerLayout;
private ListView listView;
private FrameLayout frameLayout;
private RelativeLayout relativeLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
//抽屉的跟布局
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
//选项的菜单
listView = (ListView) findViewById(R.id.list_view);
//主内容区域的布局
frameLayout = (FrameLayout) findViewById(R.id.frame_layout);
//抽屉显示的布局
relativeLayout = (RelativeLayout) findViewById(R.id.relative_layout);
final List<String> list = new ArrayList<>();
for (int i = 1; i<10;i++){
list.add(i+"");
}
//设置适配器
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_list_item_1, android.R.id.text1, list);
listView.setAdapter(arrayAdapter);
//条目的点击事件
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//要有一个fragment替换后面主内容的frameLayout
WeiXinFragment weiXinFragment = new WeiXinFragment();
//传值过去
Bundle bundle = new Bundle();
bundle.putString("key",list.get(i));
weiXinFragment.setArguments(bundle);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout,weiXinFragment).commit();
//关闭抽屉
drawerLayout.closeDrawer(relativeLayout);
}
});
}
}