private ListView getCorrectListView() { if (mListView.getParent() == null) { return mListView; } else { ((ViewGroup) mListView.getParent()).removeView(mListView); return mListView; } }
/** * Sets the list to be used in this pull to refresh container. * @param list the list to use */ public void setList(ListView list) { if (mList != null) { mContainer.removeView(mList); } mList = list; if (mList.getParent() != null) { ViewGroup parent = (ViewGroup) mList.getParent(); parent.removeView(mList); } mList.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, getHeight())); mContainer.addView(mList, 1); }
private void showNotOnlineNotification(View V) { if (getView() != null) { V = getView(); } progressBarRecentShows = (ProgressBar) V.findViewById(R.id.progressBar_recent_shows); progressBarRecentShows.setVisibility(View.GONE); listViewRecentShows = (ListView) V.findViewById(R.id.listview_recent_shows); final View emptyView = getActivity().getLayoutInflater().inflate(R.layout.empty_list, null); ((ViewGroup) listViewRecentShows.getParent()).addView(emptyView); listViewRecentShows.setEmptyView(emptyView); buttonRefresh = (Button) V.findViewById(R.id.button_refresh); buttonRefresh.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { ((ViewGroup) listViewRecentShows.getParent()).removeView(emptyView); progressBarRecentShows.setVisibility(View.VISIBLE); startRetrievingOnlineData(v); } }); }
/** 通讯模块,通知,聊天,球队没有数据的时候提示方法 */ public void setEmptyView(ListView lv, View emptyView, int res) { ViewGroup parentView = (ViewGroup) lv.getParent(); parentView.addView(emptyView); TextView warn = (TextView) emptyView.findViewById(R.id.empty_view_nearby_tv); warn.setText(res); lv.setEmptyView(emptyView); }
private void restrictDamagesListHeight() { if (adapter.getCount() < 5) { View item = adapter.getView(0, null, damagesListView); item.measure(0, 0); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( getResources().getDimensionPixelSize(R.dimen.component_standard_size), (int) (5.5 * item.getMeasuredHeight())); damagesListView.setLayoutParams(params); } if (adapter.getCount() >= 5) { // show no more than 8 damages, and not less than 5 int showNb = Math.min(adapter.getCount(), 5); View item = adapter.getView(0, null, damagesListView); item.measure(0, 0); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( getResources().getDimensionPixelSize(R.dimen.component_standard_size), (int) ((showNb + 0.5) * item.getMeasuredHeight())); damagesListView.setLayoutParams(params); } damagesListView.requestLayout(); damagesListView.getParent().requestLayout(); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.account_settings_edit_quick_responses_fragment, container, false); final ListView listView = UiUtilities.getView(view, R.id.account_settings_quick_responses_list); final TextView emptyView = UiUtilities.getView((ViewGroup) listView.getParent(), R.id.empty_view); listView.setEmptyView(emptyView); listView.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final Cursor c = (Cursor) listView.getItemAtPosition(position); final String quickResponseText = c.getString(c.getColumnIndex(UIProvider.QuickResponseColumns.TEXT)); final Uri uri = Utils.getValidUri( c.getString(c.getColumnIndex(UIProvider.QuickResponseColumns.URI))); EditQuickResponseDialog.newInstance(quickResponseText, uri, false) .show(getFragmentManager(), null); } }); return view; }
public void initLayout(final ListView leftView, ListView middleView) { this.leftView = leftView; this.middleView = middleView; this.parentView = (ViewGroup) middleView.getParent(); parentView.setVisibility(INVISIBLE); arrowView = (ImageView) findViewById(R.id.img_arrow); leftView.setOnScrollListener( new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { // To change body of implemented methods use File | Settings | File Templates. } @Override public void onScroll( AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (leftView.getChildAt(0) != null) { int deltaY = tempScrollY - getScroll(); tempScrollY = getScroll(); arrowView.setY(arrowView.getY() + deltaY); } } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.trans_list); this.findViewById(R.id.topInfoView); ((TextView) this.findViewById(R.id.titleView)).setText(R.string.historyGroup); backButton = (Button) this.findViewById(R.id.backButton); backButton.setOnClickListener(this); listView = (ListView) this.findViewById(R.id.transList); // 生成适配器的Item和动态数组对应的元素 SimpleAdapter listItemAdapter = new SimpleAdapter( this, mapList, R.layout.querytransgroup_listitem, new String[] {"tranCode", "tranName", "total", "amount"}, new int[] {R.id.groupTypeID, R.id.groupType, R.id.groupCount, R.id.groupAmount}); listView.setAdapter(listItemAdapter); listView.setOnItemClickListener(this); // 设置EmptyView ImageView emptyView = new ImageView(QueryTransferHistoryGroupActivity.this); emptyView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); emptyView.setImageResource(R.drawable.nodata); emptyView.setScaleType(ScaleType.CENTER_INSIDE); ((ViewGroup) listView.getParent()).addView(emptyView); listView.setEmptyView(emptyView); // 设置数据 try { String content = this.getIntent().getStringExtra("detail"); String[] items = content.split("\\|"); for (String item : items) { HashMap<String, String> tempMap = new HashMap<String, String>(); String[] detail = item.split("\\^"); for (String str : detail) { String[] fieldArray = str.split(":"); if (fieldArray.length == 1) { tempMap.put(fieldArray[0], ""); } else if (fieldArray.length == 2) { tempMap.put(fieldArray[0], fieldArray[1]); } tempMap.put("tranName", AppDataCenter.getTransferName(tempMap.get("tranCode"))); } mapList.add(tempMap); } ((SimpleAdapter) listView.getAdapter()).notifyDataSetChanged(); } catch (Exception e) { e.printStackTrace(); } }
/** * This is mostly used to get the size of the screen to be able to get a good layout for the * buttons on the controller screen */ @Override protected void onPause() { super.onPause(); // We get the coordinate of the screen if (CurrentConfiguration.heightInPixel == -1) { RelativeLayout parent = ((RelativeLayout) controllerList.getParent()); CurrentConfiguration.heightInPixel = parent.getHeight(); CurrentConfiguration.widthInPixel = parent.getWidth(); } }
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); if (changed) { // 获取rightView所在布局的父布局 parentView = (ViewGroup) middleView.getParent(); viewWidth = this.getWidth(); leftlist_move_rate = leftlist_img_width / (viewWidth - leftlist_img_width); Log.d("LogonActivity", "SildingLayout:onLayout: leftlist_move_rate" + leftlist_move_rate); } }
private void initListView() { mPatchesAdapter = new PatchesAdapter(mContext); mPatchList = (ListView) findViewById(R.id.patch_list); TextView emptyView = new TextView(mContext); LinearLayout.LayoutParams lparam = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); lparam.weight = 1; emptyView.setLayoutParams(lparam); emptyView.setText(getString(R.string.empty)); emptyView.setVisibility(View.GONE); ((ViewGroup) mPatchList.getParent()).addView(emptyView, 2); mPatchList.setEmptyView(emptyView); mPatchList.setFastScrollEnabled(true); mPatchList.setDivider(new ColorDrawable(0xff777777)); mPatchList.setDividerHeight(1); mPatchList.setAdapter(mPatchesAdapter); mPatchList.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { FPatch p = mPatchesAdapter.getItem(position); mInfoDialog.show( getFragmentManager(), p.packageName, "apkPath=" + p.apkPath + "\ntargetJar=" + p.targetJar); } }); mPatchList.setOnItemLongClickListener( new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { FPatch p = mPatchesAdapter.getItem(position); Intent intent = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS"); intent.setData(android.net.Uri.fromParts("package", p.packageName, null)); startActivity(intent); return true; } }); refreshList(); // mPatchesAdapter.sort(new java.util.Comparator<FPatch>() { // @Override // public int compare(FPatch lhs, FPatch rhs) { // return lhs.appName.compareTo(rhs.appName); // } // }); }
private void findViews() { classifyLayout = (View) findViewById(R.id.classifyLayout); messengerListView = (ListView) findViewById(R.id.msgListView); contactPersonListView = (ListView) findViewById(R.id.favoriteContactPersonListView); rightArrowImageView = (ImageView) findViewById(R.id.classifySmsImageView); rightArrowImageView.setOnClickListener(this); // tabControlImageView = (ImageView) findViewById(R.id.tabControlImageView); // tabControlImageView.setOnClickListener(this); dialogListLayout = (LinearLayout) messengerListView.getParent(); tabContainerLayout = (LinearLayout) findViewById(R.id.tabContainerLayout); smsTabTitleTextView = (TextView) findViewById(R.id.smsTabTitleTextView); smsTabTitleTextView.setOnClickListener(this); // set linearlayout params DisplayMetrics metric = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metric); int mScreenWidth = metric.widthPixels; dialogListLayout.setLayoutParams(new LayoutParams(mScreenWidth, LayoutParams.FILL_PARENT)); dialogListLayout.setBackgroundResource(R.color.bg_color); dialogListLayout.requestLayout(); }
private void setDishes() { mDishLstAdapter = new DishListAdapter(this, mDishes) { @Override public View getView(int position, View convertView, ViewGroup arg2) { if (Info.getMode() == Info.WORK_MODE_CUSTOMER) { return getMenuView(position, convertView); } else { return getFastOrderMenu(position, convertView); } } }; if (mCategories.count() <= 0) { return; } mDishLstTitle.setText(mCategories.getName(0)); mDishesLst.setAdapter(mDishLstAdapter); View emptyView = getLayoutInflater().inflate(R.layout.empty_list, null); ((ViewGroup) mDishesLst.getParent()) .addView(emptyView, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); mDishesLst.setEmptyView(emptyView); updateDishes(0); }
/** * Called when the activity is first created. Sets up the view. * * @param savedInstanceState Um I don't even know. Read the Android documentation. */ @Override public void onCreate(Bundle savedInstanceState) { String TAG = StaticBlob.TAG(); if (android.os.Build.VERSION.SDK_INT >= 11) setTheme(R.style.Default_New); // General create stuff super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); Log.v(TAG, "Launching Activity"); mainListView = new ListView(this); Callisto.build_layout(this, mainListView); // Get the settings for this show currentShow = getIntent().getExtras().getString("current_show"); currentShowAudio = getIntent().getExtras().getString("current_show_audio"); currentShowVideo = getIntent().getExtras().getString("current_show_video"); showSettings = getSharedPreferences(currentShow, 0); filter = showSettings.getBoolean("filter", false); loading = (TextView) findViewById(android.R.id.empty); // If it has been checked before but there are no episodes, show that it is empty, not just // loading. if (StaticBlob.databaseConnector.getShow(currentShow, filter).getCount() == 0) loading.setText(this.getResources().getString(R.string.list_empty)); else loading.setText(this.getResources().getString(R.string.loading)); loading.setGravity(Gravity.CENTER_HORIZONTAL); // If it has never been checked before add a refresh button if (showSettings.getString("last_checked", null) == null) { refresh = new Button(this); refresh.setText(this.getResources().getString(R.string.refresh)); refresh.setTextColor(this.getResources().getColor(R.color.txtClr)); LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); p.setMargins(20, 10, 20, 10); refresh.setLayoutParams(p); ((LinearLayout) loading.getParent()).setGravity(Gravity.CENTER_HORIZONTAL); refresh.setPadding(100, 10, 100, 10); refresh.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { reload(); } }); ((LinearLayout) mainListView.getParent()).addView(refresh, 1); ((LinearLayout) mainListView.getParent()) .setBackgroundColor(this.getResources().getColor(R.color.backClr)); mainListView.setEmptyView(refresh); loading.setVisibility(View.INVISIBLE); } else { mainListView.setEmptyView(loading); } // Finish setting up the listview mainListView.setOnItemClickListener(selectEpisode); mainListView.setBackgroundColor(getResources().getColor(R.color.backClr)); mainListView.setCacheColorHint(getResources().getColor(R.color.backClr)); setTitle(currentShow); // Get the shows from the SQL; make it async because of reasons new GetShowTask().execute((Object[]) null); Cursor r = StaticBlob.databaseConnector.getShow(currentShow, filter); showAdapter = new ShowListCursorAdapter(ShowList.this, R.layout.row, r); mainListView.setAdapter(showAdapter); return; }
@Override public void onStart() { if (reload) { getPoiAdapter().clear(); reload = false; } DiscoverTrentoActivity.mDrawerToggle.setDrawerIndicatorEnabled(false); DiscoverTrentoActivity.drawerState = "off"; getSherlockActivity().getSupportActionBar().setHomeButtonEnabled(true); getSherlockActivity().getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSherlockActivity().getSupportActionBar().setDisplayShowTitleEnabled(true); Bundle bundle = this.getArguments(); String category = (bundle != null) ? bundle.getString(SearchFragment.ARG_CATEGORY) : null; CategoryDescriptor catDescriptor = CategoryHelper.getCategoryDescriptorByCategoryFiltered("pois", category); String categoryString = (catDescriptor != null) ? context.getResources().getString(catDescriptor.description) : null; // set title TextView title = (TextView) getView().findViewById(R.id.list_title); if (categoryString != null) { title.setText(categoryString); } else if (bundle != null && bundle.containsKey(SearchFragment.ARG_QUERY)) { String query = bundle.getString(SearchFragment.ARG_QUERY); title.setText(context.getResources().getString(R.string.search_for) + "'" + query + "'"); if (bundle.containsKey(SearchFragment.ARG_CATEGORY_SEARCH)) { category = bundle.getString(SearchFragment.ARG_CATEGORY_SEARCH); if (category != null) title.append( " " + context.getResources().getString(R.string.search_for) + " " + categoryString); } } if (bundle.containsKey(SearchFragment.ARG_WHERE_SEARCH)) { WhereForSearch where = bundle.getParcelable(SearchFragment.ARG_WHERE_SEARCH); if (where != null) title.append(" " + where.getDescription() + " "); } // close items menus if open ((View) list.getParent()) .setOnClickListener( new View.OnClickListener() { public void onClick(View v) { hideListItemsMenu(v, false); } }); list.setOnItemClickListener( new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { hideListItemsMenu(view, false); setStorePoiId(view, position); } }); FeedbackFragmentInflater.inflateHandleButton(getSherlockActivity(), getView()); super.onStart(); }
@Override public void onDestroyView() { super.onDestroyView(); ViewParent p = _lv.getParent(); if (p != null) ((ViewGroup) p).removeView(_lv); }
/** * Initializing the QuickScroll, this function must be called. * * <p> * * @param type the QuickScroll type. Available inputs: <b>QuickScroll.TYPE_POPUP</b> or * <b>QuickScroll.TYPE_INDICATOR</b> * @param list the ListView * @param scrollable the adapter, must implement Scrollable interface */ public void init( final int type, final ListView list, final Scrollable scrollable, final int style) { if (mInitialized) return; mType = type; mList = list; mScrollable = scrollable; mGroupPosition = -1; mFadeIn = new AlphaAnimation(.0f, 1.0f); mFadeIn.setFillAfter(true); mFadeOut = new AlphaAnimation(1.0f, .0f); mFadeOut.setFillAfter(true); mFadeOut.setAnimationListener( new AnimationListener() { public void onAnimationStart(Animation animation) {} public void onAnimationRepeat(Animation animation) {} public void onAnimationEnd(Animation animation) { mScrolling = false; } }); mScrolling = false; final float density = getResources().getDisplayMetrics().density; mList.setOnTouchListener( new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (mScrolling && (event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_DOWN)) { return true; } return false; } }); final RelativeLayout.LayoutParams containerparams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); final RelativeLayout container = new RelativeLayout(getContext()); container.setBackgroundColor(Color.TRANSPARENT); containerparams.addRule(RelativeLayout.ALIGN_TOP, getId()); containerparams.addRule(RelativeLayout.ALIGN_BOTTOM, getId()); container.setLayoutParams(containerparams); if (mType == TYPE_POPUP || mType == TYPE_POPUP_WITH_HANDLE) { mScrollIndicatorText = new TextView(getContext()); mScrollIndicatorText.setTextColor(Color.WHITE); mScrollIndicatorText.setVisibility(View.INVISIBLE); mScrollIndicatorText.setGravity(Gravity.CENTER); final RelativeLayout.LayoutParams popupparams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); popupparams.addRule(RelativeLayout.CENTER_IN_PARENT); mScrollIndicatorText.setLayoutParams(popupparams); setPopupColor(GREY_LIGHT, GREY_DARK, 1, Color.WHITE, 1); setTextPadding(mTextPadding, mTextPadding, mTextPadding, mTextPadding); container.addView(mScrollIndicatorText); } else if (mType == TYPE_INDICATOR || mType == TYPE_INDICATOR_WITH_HANDLE) { mScrollIndicator = createPin(); mScrollIndicatorText = (TextView) mScrollIndicator.findViewById(ID_PIN_TEXT); (mScrollIndicator.findViewById(ID_PIN)).getLayoutParams().width = 25; container.addView(mScrollIndicator); } // setting scrollbar width getLayoutParams().width = (int) (30 * density); mScrollIndicatorText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 32); // scrollbar setup if (style != STYLE_NONE) { final RelativeLayout layout = new RelativeLayout(getContext()); final RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); params.addRule(RelativeLayout.ALIGN_LEFT, getId()); params.addRule(RelativeLayout.ALIGN_TOP, getId()); params.addRule(RelativeLayout.ALIGN_RIGHT, getId()); params.addRule(RelativeLayout.ALIGN_BOTTOM, getId()); layout.setLayoutParams(params); mScrollbar = new View(getContext()); mScrollbar.setBackgroundColor(GREY_SCROLLBAR); final RelativeLayout.LayoutParams scrollbarparams = new RelativeLayout.LayoutParams(1, LayoutParams.MATCH_PARENT); scrollbarparams.addRule(RelativeLayout.CENTER_HORIZONTAL); scrollbarparams.topMargin = mScrollbarMargin; scrollbarparams.bottomMargin = mScrollbarMargin; mScrollbar.setLayoutParams(scrollbarparams); layout.addView(mScrollbar); ((ViewGroup) mList.getParent()).addView(layout); // creating the handlebar if (mType == TYPE_INDICATOR_WITH_HANDLE || mType == TYPE_POPUP_WITH_HANDLE) { mHandlebar = new View(getContext()); setHandlebarColor(BLUE_LIGHT, BLUE_LIGHT, BLUE_LIGHT_SEMITRANSPARENT); final RelativeLayout.LayoutParams handleparams = new RelativeLayout.LayoutParams((int) (12 * density), (int) (36 * density)); mHandlebar.setLayoutParams(handleparams); ((RelativeLayout.LayoutParams) mHandlebar.getLayoutParams()) .addRule(RelativeLayout.CENTER_HORIZONTAL); layout.addView(mHandlebar); mList.setOnScrollListener( new OnScrollListener() { public void onScrollStateChanged(AbsListView view, int scrollState) {} @SuppressLint("NewApi") public void onScroll( AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (!mScrolling && totalItemCount - visibleItemCount > 0) { moveHandlebar( getHeight() * firstVisibleItem / (totalItemCount - visibleItemCount)); } } }); } } mInitialized = true; ((ViewGroup) mList.getParent()).addView(container); }
/** Set the ContentView to be either the grid of thumbnails or the vertical list. */ private void switchViewMode(BookmarkViewMode viewMode) { if (mViewMode == viewMode) { return; } mViewMode = viewMode; // Update the preferences to make the new view mode sticky. Editor ed = getPreferences(MODE_PRIVATE).edit(); if (mMostVisited) { ed.putInt(PREF_MOST_VISITED_VIEW_MODE, mViewMode.ordinal()); } else { ed.putInt(PREF_BOOKMARK_VIEW_MODE, mViewMode.ordinal()); } ed.apply(); if (mBookmarksAdapter != null) { mBookmarksAdapter.switchViewMode(viewMode); } if (mViewMode == BookmarkViewMode.GRID) { if (mGridPage == null) { mGridPage = new GridView(this); if (mBookmarksAdapter != null) { mGridPage.setAdapter(mBookmarksAdapter); } mGridPage.setOnItemClickListener(mListener); mGridPage.setNumColumns(GridView.AUTO_FIT); mGridPage.setColumnWidth(BrowserActivity.getDesiredThumbnailWidth(this)); mGridPage.setFocusable(true); mGridPage.setFocusableInTouchMode(true); mGridPage.setSelector(android.R.drawable.gallery_thumb); float density = getResources().getDisplayMetrics().density; mGridPage.setVerticalSpacing((int) (14 * density)); mGridPage.setHorizontalSpacing((int) (8 * density)); mGridPage.setStretchMode(GridView.STRETCH_SPACING); mGridPage.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET); mGridPage.setDrawSelectorOnTop(true); if (mMostVisited) { mGridPage.setEmptyView(mEmptyView); } if (!mCreateShortcut) { mGridPage.setOnCreateContextMenuListener(this); } } addContentView(mGridPage, FULL_SCREEN_PARAMS); if (mVerticalList != null) { ViewGroup parent = (ViewGroup) mVerticalList.getParent(); if (parent != null) { parent.removeView(mVerticalList); } } } else { if (null == mVerticalList) { ListView listView = new ListView(this); if (mBookmarksAdapter != null) { listView.setAdapter(mBookmarksAdapter); } listView.setDrawSelectorOnTop(false); listView.setVerticalScrollBarEnabled(true); listView.setOnItemClickListener(mListener); if (mMostVisited) { listView.setEmptyView(mEmptyView); } if (!mCreateShortcut) { listView.setOnCreateContextMenuListener(this); } mVerticalList = listView; } addContentView(mVerticalList, FULL_SCREEN_PARAMS); if (mGridPage != null) { ViewGroup parent = (ViewGroup) mGridPage.getParent(); if (parent != null) { parent.removeView(mGridPage); } } } }