我使用此代码将项目添加到我的 ListViews(菜单和主屏幕),但它仅适用于主屏幕
final Context context = this ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView lv = (ListView) findViewById(R.id.listView1);
String[] items = new String[]{"xxx","xxx","xxx","xxx"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context ,android.R.layout.simple_list_item_1, android.R.id.text1, items);
lv.setAdapter(adapter);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.menu_frame, null);
ListView lv2 = (ListView) view.findViewById(R.id.listView2);
TextView tv2 = (TextView) view.findViewById(R.id.textView2);
tv2.setText("Hello Mahdi");
String[] items2 = new String[]{"xxx","xxx","xxx","xxx"};
ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(context ,android.R.layout.simple_list_item_1, android.R.id.text1, items2);
lv2.setAdapter(adapter2);
SlidingMenu menu;
menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setShadowWidth(5);
menu.setFadeDegree(0.0f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
menu.setBehindWidth(200);
menu.setMenu(R.layout.menu_frame);
}