/** * method to populate one menu list * * @param menuList * @param listTitle * @param menuNames * @param menuIcons */ private ListView setupList(String listTitle, String[] menuNames, int[] menuIcons) { SimpleAdapter menuAdapter = new SimpleAdapter(getActivity()); for (int i = 0; i < menuNames.length; i++) { listObject menuObject = new listObject(); menuObject.setText(menuNames[i]); menuObject.setResID(menuIcons[i]); menuAdapter.add(menuObject); } LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); View headerview = layoutInflater.inflate(R.layout.sliding_menu_list_header, null); TextView listHeaderName = (TextView) headerview.findViewById(R.id.sliding_menu_list_name); listHeaderName.setTypeface(font); listHeaderName.setText(listTitle); ListView menuList = new ListView(parentActivity); menuList.setLayoutParams(params); int sizeInPx = 10; float scale = getResources().getDisplayMetrics().density; int sizeInDp = (int) (sizeInPx * scale + 0.5f); menuList.setPadding(sizeInDp, 0, sizeInDp, 0); // menuList.setPadding(R.dimen.list_padding, 0, R.dimen.list_padding, 0); menuList.addHeaderView(headerview); menuList.setAdapter(menuAdapter); listRoot.addView(menuList, params); return menuList; }
@NotNull @Override public SimpleAdapter marshal(@NotNull final XmlSerializable v) throws Exception { final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); final Document document = dbf.newDocumentBuilder().newDocument(); final DocumentFragment content = document.createDocumentFragment(); final XMLOutputFactory xof = XMLOutputFactory.newFactory(); final XMLStreamWriter out = xof.createXMLStreamWriter(new DOMResult(content)); v.serialize(XmlStreaming.newWriter(new DOMResult(content))); final int childCount = content.getChildNodes().getLength(); if (childCount == 0) { return new SimpleAdapter(); } else if (childCount == 1) { final SimpleAdapter result = new SimpleAdapter(); final Node child = content.getFirstChild(); if (child instanceof Element) { result.setAttributes(child.getAttributes()); for (Node child2 = child.getFirstChild(); child2 != null; child2 = child2.getNextSibling()) { result.children.add(child2); } } else { result.children.add(child); } return result; } else { // More than one child final SimpleAdapter result = new SimpleAdapter(); for (Node child = content.getFirstChild(); child != null; child = child.getNextSibling()) { result.children.add(child); } return result; } }
@Override public boolean onOptionsItemSelected(MenuItem item) { NumberPickerDialog dialog; switch (item.getItemId()) { case R.id.action_add: dialog = new NumberPickerDialog(getActivity()); dialog.setTitle("Position to Add"); dialog.setPickerRange(0, mAdapter.getItemCount() - 1); dialog.setOnNumberSelectedListener( new NumberPickerDialog.OnNumberSelectedListener() { @Override public void onNumberSelected(int value) { mAdapter.addItem(value); } }); dialog.show(); return true; case R.id.action_remove: dialog = new NumberPickerDialog(getActivity()); dialog.setTitle("Position to Remove"); dialog.setPickerRange(0, mAdapter.getItemCount() - 1); dialog.setOnNumberSelectedListener( new NumberPickerDialog.OnNumberSelectedListener() { @Override public void onNumberSelected(int value) { mAdapter.removeItem(value); } }); dialog.show(); return true; case R.id.action_empty: mAdapter.setItemCount(0); return true; case R.id.action_small: mAdapter.setItemCount(5); return true; case R.id.action_medium: mAdapter.setItemCount(25); return true; case R.id.action_large: mAdapter.setItemCount(196); return true; case R.id.action_scroll_zero: mRecyclerView.scrollToPosition(0); return true; case R.id.action_smooth_zero: mRecyclerView.smoothScrollToPosition(0); return true; default: return super.onOptionsItemSelected(item); } }
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); setHasOptionsMenu(true); mRecyclerView = (RecyclerView) view.findViewById(R.id.fixed_two_way_recyclerview); TwoWayGridLayoutManager manager = new TwoWayGridLayoutManager(); manager.setTotalColumnCount(10); mRecyclerView.setLayoutManager(manager); mRecyclerView.addItemDecoration(new InsertDecoration(getActivity())); mRecyclerView.getItemAnimator().setAddDuration(1000); mRecyclerView.getItemAnimator().setChangeDuration(1000); mRecyclerView.getItemAnimator().setMoveDuration(1000); mRecyclerView.getItemAnimator().setRemoveDuration(1000); mAdapter = new SimpleAdapter(); mAdapter.setItemCount(12); mRecyclerView.setAdapter(mAdapter); }
@OnItemClick(R.id.list_of_things) void onItemClick(int position) { Toast.makeText(this, "You clicked: " + adapter.getItem(position), LENGTH_SHORT).show(); }
/** @Method: albumPopupwin @Description: menuPopupwindow�����ü���Ӧ */ private void albumPopupwin() { ListView popList; ImageView popImage; SimpleAdapter adapter; List<Map<String, Object>> foldersList = new ArrayList<Map<String, Object>>(); LayoutInflater mLayoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); ViewGroup menuView = (ViewGroup) mLayoutInflater.inflate(R.layout.listview_pop, null, true); popList = (ListView) menuView.findViewById(R.id.poplistview); popImage = (ImageView) menuView.findViewById(R.id.poplistviewimage); // popwindow �ı��� popImage.setImageDrawable(getResources().getDrawable(R.drawable.pop_titleimg)); // ��������ʽ adapter = new SimpleAdapter( this, foldersList, R.layout.smallinsidelistview, new String[] {"albumName", "picnum", "img"}, new int[] {R.id.smalluserName, R.id.smallipInfo, R.id.smalluserImg}); popList.setAdapter(adapter); foldersList.clear(); for (int i = 1; i < albumArray.length; i += 2) { HashMap<String, Object> map = new HashMap<String, Object>(); map.put("albumName", albumArray[i]); map.put("picnum", albumArray[i + 1] + "��"); map.put("img", R.drawable.folder); foldersList.add(map); adapter.notifyDataSetChanged(); } popList.requestFocus(); popList.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { Log.d("debug", albumArray.length + ""); choosedAlbum = albumArray[arg2 * 2 + 1]; uploadThread = new Thread(uploadRunnable); // ����һ�����߳� uploadThread.start(); albumPopupWindow.dismiss(); // ���ѡ��� showProgress(); // ����� } }); popList.setOnKeyListener( new OnKeyListener() { // ���㵽��gridview�ϣ�������Ҫ����˴��ļ����¼����������ֲ���Ӧ�����¼������ @Override public boolean onKey(View v, int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_MENU: if (albumPopupWindow != null && albumPopupWindow.isShowing()) { albumPopupWindow.dismiss(); } break; } System.out.println("menuGridfdsfdsfdfd"); return true; } }); int poplength = (albumArray.length - 1) * 53 + 65; Log.d("10", albumArray.length + ""); if (poplength > 595) poplength = 595; albumPopupWindow = new PopupWindow(menuView, 300, poplength, true); albumPopupWindow.setBackgroundDrawable(new BitmapDrawable()); albumPopupWindow.setAnimationStyle(R.style.PopupAnimation); albumPopupWindow.showAtLocation(findViewById(R.id.filpperparent), Gravity.CENTER, 0, 0); albumPopupWindow.update(); }