List of usage examples for android.widget GridView setNumColumns
public void setNumColumns(int numColumns)
From source file:com.example.h156252.connected_cars.CarGrid.java
/** Called when the activity is first created. */ @Override/*from ww w. j av a2 s . co m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.content_car_grid); try { Window window = getWindow(); // clear FLAG_TRANSLUCENT_STATUS flag: window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); // add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); // finally change the color window.setStatusBarColor(Color.rgb(0, 0, 0)); android.support.v7.app.ActionBar actionBar = getSupportActionBar(); actionBar.setBackgroundDrawable(new ColorDrawable(Color.rgb(0, 0, 0))); } catch (Exception e) { // Toast.makeText(getApplicationContext(),"Exception in actionbar "+e.getLocalizedMessage(),Toast.LENGTH_SHORT).show(); } session = new SessionManagement(this); tts = new TextToSpeech(this, this); //Toast.makeText(getApplicationContext(),"Entering activity",Toast.LENGTH_SHORT).show(); Intent intent = getIntent(); String result = intent.getStringExtra(HomeScreen.EXTRA_MESSAGE); //Toast.makeText(getApplicationContext(),"obtaining result: " +result,Toast.LENGTH_SHORT).show(); ArrayList<String> listdata = new ArrayList<String>(); try { JSONArray jArray = new JSONArray(result); if (jArray != null) { for (int i = 0; i < jArray.length(); i++) { String jstr = jArray.get(i).toString(); JSONObject jObj = new JSONObject(jstr); String id = jObj.getString("id"); //String phone = jObj.getString("phone"); String brand = jObj.getString("text"); String text = jObj.getString("cartext"); String carno = jObj.getString("carnum"); String color = jObj.getString("color"); //String isDone = jObj.getString("isDone"); String result_combine = "CAR " + i + ":\nCar id : #" + id + "*\n" + "License No. : " + carno + "\n" + "Color : " + color + "\n" + "Brand : " + brand + "\n" + "Text behind car : " + text; String rr = "Success " + result_combine; //Toast.makeText(getApplicationContext(),rr,Toast.LENGTH_SHORT).show(); String own_id = session.getID(); if (!(id.equals(own_id))) listdata.add(result_combine); } } } catch (Exception e) { //Toast.makeText(getApplicationContext(),e.getLocalizedMessage(),Toast.LENGTH_SHORT).show(); } //Toast.makeText(getApplicationContext(),"out of json",Toast.LENGTH_SHORT).show(); final GridView gridview = (GridView) findViewById(R.id.gridview); // final String[] items = new String[] { "Item1", "Item2", "Item3","Item4", "Item5", "Item6", "Item7", "Item8" }; ArrayAdapter<String> ad = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, listdata); //Toast.makeText(getApplicationContext(),"setting array adapter",Toast.LENGTH_SHORT).show(); //gridview.setBackgroundColor(Color.GRAY); gridview.setNumColumns(2); gridview.setGravity(Gravity.CENTER); gridview.setAdapter(ad); gridview.setBackgroundColor(Color.GRAY); //Toast.makeText(getApplicationContext(),"setting grid view",Toast.LENGTH_SHORT).show(); gridview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View v, int position, long arg3) { // TODO Auto-generated method stub // Toast.makeText(getApplicationContext(), "" + arg2,Toast.LENGTH_SHORT).show(); //Toast.makeText(getApplicationContext(),"Prompting speech",Toast.LENGTH_SHORT).show(); try { String s = ((TextView) v).getText().toString(); int start = 0; // '(' position in string int end = 0; // ')' position in string for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == '#') // Looking for '(' position in string start = i; else if (s.charAt(i) == '*') // Looking for ')' position in string end = i; } receiver_id = s.substring(start + 1, end); //Toast.makeText(getApplicationContext(), "ID: " + receiver_id, Toast.LENGTH_SHORT).show(); //promptSpeechInput(); } catch (Exception e) { // Toast.makeText(getApplicationContext(), e.getLocalizedMessage(), Toast.LENGTH_SHORT).show(); } //receiver_id = grid_text.substring(grid_text.indexOf("#") + 1, grid_text.indexOf("#")); //Toast.makeText(getApplicationContext(),receiver_id,Toast.LENGTH_SHORT).show(); try { promptSpeechInput(); } catch (Exception e) { //Toast.makeText(getApplicationContext(), e.getLocalizedMessage(), Toast.LENGTH_SHORT).show(); } try { Intent intent_rate = new Intent(getApplicationContext(), RateDriving.class); intent_rate.putExtra(EXTRA_MESSAGE, receiver_id); startActivity(intent_rate); } catch (Exception e) { //Toast.makeText(getApplicationContext(), e.getLocalizedMessage(), Toast.LENGTH_SHORT).show(); } //new VoiceTask().execute("http://myfirst.au-syd.mybluemix.net/api/Items"); } }); }
From source file:com.github.jvanhie.discogsscrobbler.ReleaseListFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); //call listener to determine correct width when available or changed getView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override/*ww w .ja v a2s . c o m*/ public void onGlobalLayout() { int fragmentWidth = getView().getWidth(); if (fragmentWidth > 0) { if (mGrid) { GridView grid = (GridView) mList; int col = grid.getNumColumns(); int newCol = Math.round((fragmentWidth / logicalDensity) / (float) 150); if (col != newCol) { int pos = grid.getFirstVisiblePosition(); //if an item is selected, focus on this instead if (mActivatedPosition != ListView.INVALID_POSITION) pos = mActivatedPosition; grid.setNumColumns(newCol); grid.setSelection(pos); } } } } }); }
From source file:org.videolan.vlc.gui.video.VideoGridFragment.java
private void updateViewMode() { if (getView() == null || getActivity() == null) { Log.w(TAG, "Unable to setup the view"); return;//from ww w . j av a 2 s. c o m } GridView gv = (GridView) getView().findViewById(android.R.id.list); // Compute the left/right padding dynamically DisplayMetrics outMetrics = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(outMetrics); int sidePadding = (int) (outMetrics.widthPixels / 100 * Math.pow(outMetrics.density, 3) / 2); sidePadding = Math.max(0, Math.min(100, sidePadding)); gv.setPadding(sidePadding, gv.getPaddingTop(), sidePadding, gv.getPaddingBottom()); // Select between grid or list if (hasSpaceForGrid(getView())) { Log.d(TAG, "Switching to grid mode"); gv.setNumColumns(GridView.AUTO_FIT); gv.setStretchMode(GRID_STRETCH_MODE); gv.setHorizontalSpacing(Util.convertDpToPx(GRID_HORIZONTAL_SPACING_DP)); gv.setVerticalSpacing(Util.convertDpToPx(GRID_VERTICAL_SPACING_DP)); gv.setColumnWidth(Util.convertDpToPx(GRID_ITEM_WIDTH_DP)); mVideoAdapter.setListMode(false); } else { Log.e(TAG, "Switching to list mode"); gv.setNumColumns(1); gv.setStretchMode(LIST_STRETCH_MODE); gv.setHorizontalSpacing(LIST_HORIZONTAL_SPACING_DP); gv.setVerticalSpacing(Util.convertDpToPx(LIST_VERTICAL_SPACING_DP)); mVideoAdapter.setListMode(true); } }
From source file:de.baumann.thema.RequestActivity.java
@SuppressWarnings("unchecked") private void populateView(ArrayList arrayListFinal) { ArrayList<AppInfo> local_arrayList; local_arrayList = arrayListFinal;//from ww w.j a v a2 s.c o m GridView grid = (GridView) findViewById(R.id.appgrid); assert grid != null; grid.setVerticalSpacing(GridView.AUTO_FIT); grid.setHorizontalSpacing(GridView.AUTO_FIT); grid.setStretchMode(GridView.STRETCH_COLUMN_WIDTH); grid.setFastScrollEnabled(true); grid.setFastScrollAlwaysVisible(true); if (DEBUG) Log.v(TAG, "height: " + getDisplaySize("height") + "; width: " + getDisplaySize("width")); AppAdapter appInfoAdapter; if (isPortrait()) { grid.setNumColumns(numCol_Portrait); if (isTablet(context)) { grid.setNumColumns(numCol_Portrait); //Here you can change the number of columns for Tablets if (DEBUG) Log.v(TAG, "isTablet"); } if (isXLargeTablet(context)) { grid.setNumColumns(numCol_Portrait); //Here you can change the number of columns for Large Tablets if (DEBUG) Log.v(TAG, "isXLargeTablet"); } appInfoAdapter = new AppAdapter(this, R.layout.request_item_list, local_arrayList); } else { grid.setNumColumns(numCol_Landscape); if (isTablet(context)) { grid.setNumColumns(numCol_Landscape); //Here you can change the number of columns for Tablets if (DEBUG) Log.v(TAG, "isTablet"); } if (isXLargeTablet(context)) { grid.setNumColumns(numCol_Landscape); //Here you can change the number of columns for Large Tablets if (DEBUG) Log.v(TAG, "isXLargeTablet"); } appInfoAdapter = new AppAdapter(this, R.layout.request_item_grid, local_arrayList); } grid.setAdapter(appInfoAdapter); grid.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> AdapterView, View view, int position, long row) { AppInfo appInfo = (AppInfo) AdapterView.getItemAtPosition(position); CheckBox checker = (CheckBox) view.findViewById(R.id.CBappSelect); ViewSwitcher icon = (ViewSwitcher) view.findViewById(R.id.viewSwitcherChecked); LinearLayout localBackground = (LinearLayout) view.findViewById(R.id.card_bg); Animation aniIn = AnimationUtils.loadAnimation(context, R.anim.request_flip_in_half_1); Animation aniOut = AnimationUtils.loadAnimation(context, R.anim.request_flip_in_half_2); checker.toggle(); appInfo.setSelected(checker.isChecked()); icon.setInAnimation(aniIn); icon.setOutAnimation(aniOut); if (appInfo.isSelected()) { if (DEBUG) Log.v(TAG, "Selected App: " + appInfo.getName()); localBackground .setBackgroundColor(ContextCompat.getColor(context, R.color.request_card_pressed)); if (icon.getDisplayedChild() == 0) { icon.showNext(); } } else { if (DEBUG) Log.v(TAG, "Deselected App: " + appInfo.getName()); localBackground .setBackgroundColor(ContextCompat.getColor(context, R.color.request_card_unpressed)); if (icon.getDisplayedChild() == 1) { icon.showPrevious(); } } } }); }
From source file:org.telegramsecureplus.ui.Components.EmojiView.java
public EmojiView(boolean needStickers, Context context) { super(context); showStickers = needStickers;//from ww w. j av a 2 s .c o m for (int i = 0; i < Emoji.data.length; i++) { GridView gridView = new GridView(context); if (AndroidUtilities.isTablet()) { gridView.setColumnWidth(AndroidUtilities.dp(60)); } else { gridView.setColumnWidth(AndroidUtilities.dp(45)); } gridView.setNumColumns(-1); views.add(gridView); EmojiGridAdapter emojiGridAdapter = new EmojiGridAdapter(Emoji.data[i]); gridView.setAdapter(emojiGridAdapter); AndroidUtilities.setListViewEdgeEffectColor(gridView, 0xfff5f6f7); adapters.add(emojiGridAdapter); } if (showStickers) { StickersQuery.checkStickers(); GridView gridView = new GridView(context); gridView.setColumnWidth(AndroidUtilities.dp(72)); gridView.setNumColumns(-1); gridView.setPadding(0, AndroidUtilities.dp(4), 0, 0); gridView.setClipToPadding(false); views.add(gridView); stickersGridAdapter = new StickersGridAdapter(context); gridView.setAdapter(stickersGridAdapter); AndroidUtilities.setListViewEdgeEffectColor(gridView, 0xfff5f6f7); stickersWrap = new FrameLayout(context); stickersWrap.addView(gridView); TextView textView = new TextView(context); textView.setText(LocaleController.getString("NoStickers", R.string.NoStickers)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); textView.setTextColor(0xff888888); stickersWrap.addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER)); gridView.setEmptyView(textView); scrollSlidingTabStrip = new ScrollSlidingTabStrip(context) { boolean startedScroll; float lastX; float lastTranslateX; boolean first = true; @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } @Override public boolean onTouchEvent(MotionEvent ev) { if (Build.VERSION.SDK_INT >= 11) { if (first) { first = false; lastX = ev.getX(); } float newTranslationX = ViewProxy.getTranslationX(scrollSlidingTabStrip); if (scrollSlidingTabStrip.getScrollX() == 0 && newTranslationX == 0) { if (!startedScroll && lastX - ev.getX() < 0) { if (pager.beginFakeDrag()) { startedScroll = true; lastTranslateX = ViewProxy.getTranslationX(scrollSlidingTabStrip); } } else if (startedScroll && lastX - ev.getX() > 0) { if (pager.isFakeDragging()) { pager.endFakeDrag(); startedScroll = false; } } } if (startedScroll) { int dx = (int) (ev.getX() - lastX + newTranslationX - lastTranslateX); try { pager.fakeDragBy(dx); lastTranslateX = newTranslationX; } catch (Exception e) { try { pager.endFakeDrag(); } catch (Exception e2) { //don't promt } startedScroll = false; FileLog.e("tmessages", e); } } lastX = ev.getX(); if (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP) { first = true; if (startedScroll) { pager.endFakeDrag(); startedScroll = false; } } return startedScroll || super.onTouchEvent(ev); } return super.onTouchEvent(ev); } }; scrollSlidingTabStrip.setUnderlineHeight(AndroidUtilities.dp(1)); scrollSlidingTabStrip.setIndicatorColor(0xffe2e5e7); scrollSlidingTabStrip.setUnderlineColor(0xffe2e5e7); addView(scrollSlidingTabStrip, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.TOP)); ViewProxy.setTranslationX(scrollSlidingTabStrip, AndroidUtilities.displaySize.x); updateStickerTabs(); scrollSlidingTabStrip.setDelegate(new ScrollSlidingTabStrip.ScrollSlidingTabStripDelegate() { @Override public void onPageSelected(int page) { if (page == 0) { pager.setCurrentItem(0); return; } else if (page == 1 && !recentStickers.isEmpty()) { views.get(6).setSelection(0); return; } int index = page - (recentStickers.isEmpty() ? 1 : 2); if (index >= stickerSets.size()) { index = stickerSets.size() - 1; } views.get(6).setSelection(stickersGridAdapter.getPositionForPack(stickerSets.get(index))); } }); gridView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView view, int scrollState) { } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { int count = view.getChildCount(); for (int a = 0; a < count; a++) { View child = view.getChildAt(a); if (child.getHeight() + child.getTop() < AndroidUtilities.dp(5)) { firstVisibleItem++; } else { break; } } scrollSlidingTabStrip .onPageScrolled(stickersGridAdapter.getTabForPosition(firstVisibleItem) + 1, 0); } }); } setBackgroundColor(0xfff5f6f7); pager = new ViewPager(context) { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } }; pager.setAdapter(new EmojiPagesAdapter()); pagerSlidingTabStripContainer = new LinearLayout(context) { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } return super.onInterceptTouchEvent(ev); } }; pagerSlidingTabStripContainer.setOrientation(LinearLayout.HORIZONTAL); pagerSlidingTabStripContainer.setBackgroundColor(0xfff5f6f7); addView(pagerSlidingTabStripContainer, LayoutHelper.createFrame(LayoutParams.MATCH_PARENT, 48)); PagerSlidingTabStrip pagerSlidingTabStrip = new PagerSlidingTabStrip(context); pagerSlidingTabStrip.setViewPager(pager); pagerSlidingTabStrip.setShouldExpand(true); pagerSlidingTabStrip.setIndicatorHeight(AndroidUtilities.dp(2)); pagerSlidingTabStrip.setUnderlineHeight(AndroidUtilities.dp(1)); pagerSlidingTabStrip.setIndicatorColor(0xff2b96e2); pagerSlidingTabStrip.setUnderlineColor(0xffe2e5e7); pagerSlidingTabStripContainer.addView(pagerSlidingTabStrip, LayoutHelper.createLinear(0, 48, 1.0f)); pagerSlidingTabStrip.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { EmojiView.this.onPageScrolled(position, getMeasuredWidth(), positionOffsetPixels); } @Override public void onPageSelected(int position) { } @Override public void onPageScrollStateChanged(int state) { } }); FrameLayout frameLayout = new FrameLayout(context); pagerSlidingTabStripContainer.addView(frameLayout, LayoutHelper.createLinear(52, 48)); backspaceButton = new ImageView(context) { @Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { backspacePressed = true; backspaceOnce = false; postBackspaceRunnable(350); } else if (event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP) { backspacePressed = false; if (!backspaceOnce) { if (EmojiView.this.listener != null && EmojiView.this.listener.onBackspace()) { backspaceButton.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP); } } } super.onTouchEvent(event); return true; } }; backspaceButton.setImageResource(R.drawable.ic_smiles_backspace); backspaceButton.setBackgroundResource(R.drawable.ic_emoji_backspace); backspaceButton.setScaleType(ImageView.ScaleType.CENTER); frameLayout.addView(backspaceButton, LayoutHelper.createFrame(52, 48)); View view = new View(context); view.setBackgroundColor(0xffe2e5e7); frameLayout.addView(view, LayoutHelper.createFrame(52, 1, Gravity.LEFT | Gravity.BOTTOM)); recentsWrap = new FrameLayout(context); recentsWrap.addView(views.get(0)); TextView textView = new TextView(context); textView.setText(LocaleController.getString("NoRecent", R.string.NoRecent)); textView.setTextSize(18); textView.setTextColor(0xff888888); textView.setGravity(Gravity.CENTER); recentsWrap.addView(textView); views.get(0).setEmptyView(textView); addView(pager, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 48, 0, 0)); loadRecents(); if (Emoji.data[0] == null || Emoji.data[0].length == 0) { pager.setCurrentItem(1); } }
From source file:org.michaelbel.bottomsheet.BottomSheet.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (backgroundColor == 0) { backgroundColor = darkTheme ? 0xFF424242 : 0xFFFFFFFF; }/*from ww w .j ava 2 s . com*/ if (titleTextColor == 0) { titleTextColor = darkTheme ? 0xB3FFFFFF : 0x8A000000; } if (itemTextColor == 0) { itemTextColor = darkTheme ? 0xFFFFFFFF : 0xDE000000; } if (iconColor == 0) { iconColor = darkTheme ? 0xFFFFFFFF : 0x8A000000; } if (itemSelector == 0) { itemSelector = darkTheme ? R.drawable.selectable_dark : R.drawable.selectable_light; } Window window = getWindow(); window.setWindowAnimations(R.style.DialogNoAnimation); setContentView(container, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); if (containerView == null) { containerView = new FrameLayout(getContext()) { @Override public boolean hasOverlappingRendering() { return false; } }; if (Build.VERSION.SDK_INT >= 16) { containerView.setBackground(shadowDrawable); } else { containerView.setBackgroundDrawable(shadowDrawable); } containerView.setPadding(0, backgroundPaddingTop, 0, Utils.dp(getContext(), 8)); } if (Build.VERSION.SDK_INT >= 21) { containerView.setFitsSystemWindows(true); } containerView.setVisibility(View.INVISIBLE); containerView.setBackgroundColor(backgroundColor); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.gravity = Gravity.BOTTOM; containerView.setLayoutParams(params); container.addView(containerView, 0); if (customView != null) { if (customView.getParent() != null) { ViewGroup viewGroup = (ViewGroup) customView.getParent(); viewGroup.removeView(customView); } FrameLayout.LayoutParams params1 = (FrameLayout.LayoutParams) containerView.getLayoutParams(); params1.width = ViewGroup.LayoutParams.MATCH_PARENT; params1.height = ViewGroup.LayoutParams.WRAP_CONTENT; params1.gravity = Gravity.START | Gravity.TOP; containerView.addView(customView, params1); } else { int topOffset = 0; if (titleText != null) { TextView titleTextView = new TextView(getContext()); titleTextView.setLines(1); titleTextView.setMaxLines(1); titleTextView.setSingleLine(true); titleTextView.setText(titleText); titleTextView.setTextColor(titleTextColor); titleTextView.setEllipsize(TextUtils.TruncateAt.MIDDLE); titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); titleTextView.setGravity(Gravity.CENTER_VERTICAL); FrameLayout.LayoutParams params0 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, Utils.dp(getContext(), 56)); params0.gravity = Gravity.START | Gravity.TOP; params0.leftMargin = Utils.dp(getContext(), 16); params0.rightMargin = Utils.dp(getContext(), 16); titleTextView.setLayoutParams(params0); containerView.addView(titleTextView); titleTextView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); topOffset += 56; } BottomSheetAdapter adapter = new BottomSheetAdapter(); if (mItems != null || mItemsRes != null) { if (contentType == LIST) { FrameLayout.LayoutParams params2 = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); params2.topMargin = Utils.dp(getContext(), topOffset); ListView listView = new ListView(getContext()); listView.setSelector(itemSelector); listView.setDividerHeight(0); listView.setAdapter(adapter); listView.setDrawSelectorOnTop(true); listView.setVerticalScrollBarEnabled(false); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { dismissWithButtonClick(i); } }); listView.setLayoutParams(params2); containerView.addView(listView); } else if (contentType == GRID) { FrameLayout.LayoutParams params3 = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); GridView gridView = new GridView(getContext()); gridView.setSelector(itemSelector); gridView.setAdapter(adapter); gridView.setNumColumns(3); gridView.setVerticalScrollBarEnabled(false); gridView.setVerticalSpacing(Utils.dp(getContext(), 16)); gridView.setPadding(Utils.dp(getContext(), 0), Utils.dp(getContext(), topOffset + 8), Utils.dp(getContext(), 0), Utils.dp(getContext(), 16)); gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { dismissWithButtonClick(i); } }); gridView.setLayoutParams(params3); containerView.addView(gridView); } if (mItems != null) { for (int a = 0; a < mItems.length; a++) { items.add(new Item(mItems[a], mIcons != null ? mIcons[a] : 0)); } } else { for (int a = 0; a < mItemsRes.length; a++) { items.add(new Item(getContext().getText(mItemsRes[a]), mIcons != null ? mIcons[a] : 0)); } } adapter.notifyDataSetChanged(); } } WindowManager.LayoutParams params4 = window.getAttributes(); params4.width = ViewGroup.LayoutParams.MATCH_PARENT; params4.gravity = Gravity.TOP | Gravity.START; params4.dimAmount = 0; params4.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND; if (!focusable) { params4.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; } params4.height = ViewGroup.LayoutParams.MATCH_PARENT; window.setAttributes(params4); }
From source file:com.abc.driver.MainActivity.java
public void chooseTruckType(View v) { mTTtv = (TextView) this.findViewById(R.id.truck_type_tv); AlertDialog.Builder builder = new AlertDialog.Builder(this); GridView gridView1 = new GridView(this); gridView1.setNumColumns(3); // (GridView)findViewById(R.id.gridView1); SimpleAdapter adapter = new SimpleAdapter(this, mTruckTypeList, R.layout.truck_type_griditem, new String[] { "PIC", "TITLE", "TTYPE" }, new int[] { R.id.griditem_pic, R.id.griditem_title, R.id.griditem_type, }); gridView1.setAdapter(adapter);// w w w.j a v a 2s . co m builder.setTitle("Please Choose"); builder.setInverseBackgroundForced(true); builder.setView(gridView1); final Dialog dialog = builder.create(); gridView1.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) { mTTtv.setText(((TextView) view.findViewById(R.id.griditem_title)).getText()); mTruckType = ((TextView) view.findViewById(R.id.griditem_type)).getText().toString(); dialog.dismiss(); } }); dialog.show(); }
From source file:com.abc.driver.MainActivity.java
public void chooseCargoType(View v) { mCTtv = (TextView) this.findViewById(R.id.cargo_type_tv); AlertDialog.Builder builder = new AlertDialog.Builder(this); GridView gridView1 = new GridView(this); gridView1.setNumColumns(3); // (GridView)findViewById(R.id.gridView1); SimpleAdapter adapter = new SimpleAdapter(this, mCargoTypeList, R.layout.cargo_type_griditem, new String[] { "PIC", "TITLE", "CTYPE" }, new int[] { R.id.griditem_pic, R.id.griditem_title, R.id.griditem_type, }); gridView1.setAdapter(adapter);//from w ww . ja v a 2 s .c o m builder.setTitle("Please Choose"); builder.setInverseBackgroundForced(true); builder.setView(gridView1); final Dialog dialog = builder.create(); gridView1.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) { // doing something in here and then close mCTtv.setText(((TextView) view.findViewById(R.id.griditem_title)).getText()); mCargoType = ((TextView) view.findViewById(R.id.griditem_type)).getText().toString(); dialog.dismiss(); } }); dialog.show(); }
From source file:com.abc.driver.MainActivity.java
public void chooseTruckLength(View v) { mTLtv = (TextView) findViewById(R.id.truck_length_tv); AlertDialog.Builder builder = new AlertDialog.Builder(this); GridView gridView1 = new GridView(this); gridView1.setNumColumns(3); // (GridView)findViewById(R.id.gridView1); SimpleAdapter adapter = new SimpleAdapter(this, mTruckLengthList, R.layout.truck_length_griditem, new String[] { "TITLE", "TLENGTH" }, new int[] { R.id.griditem_title, R.id.griditem_length, }); gridView1.setAdapter(adapter);//from w ww . j a va 2s. c o m builder.setTitle("Please Choose"); builder.setInverseBackgroundForced(true); builder.setView(gridView1); final Dialog dialog = builder.create(); gridView1.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long rowId) { mTLtv.setText(((TextView) view.findViewById(R.id.griditem_title)).getText()); mTruckLength = ((TextView) view.findViewById(R.id.griditem_length)).getText().toString(); dialog.dismiss(); } }); // */ dialog.show(); }
From source file:com.example.spencerdepas.translationapp.activities.DMVSimulationActivity.java
private void showSelectQuestionDialog() { Log.d(TAG, "showAlertDialog"); // Prepare grid view GridView gridView = new GridView(this); List<Integer> mList = new ArrayList<Integer>(); for (int i = 1; i < 21; i++) { mList.add(i);//from ww w . j a va 2 s. c om } // gridView.setAdapter(new ArrayAdapter<>(this, R.layout.custom_list_item, mList)); gridView.setAdapter(new ArrayAdapter<Integer>(this, R.layout.custom_list_item, mList) { @Override public View getView(int position, View convertView, ViewGroup parent) { View view = super.getView(position, convertView, parent); boolean hasBeenAnswered = hasBeenAnswered(position); int color = 0x00FFFFFF; // Transparent if (hasBeenAnswered) { view.setBackgroundColor(getResources().getColor(R.color.colorForQuestionGrid)); } else { view.setBackgroundColor(color); } return view; } }); gridView.setNumColumns(4); // Set grid view to alertDialog final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(gridView); builder.setTitle(getResources().getString(R.string.select_question)); builder.setPositiveButton(getResources().getString(R.string.dialog_dismiss), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Log.d(TAG, "DISMISS"); dialog.dismiss(); } }); final AlertDialog ad = builder.show(); gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // do something here Log.d(TAG, "onclick"); saveAnswer(); unSelectRadioButtons(); loadRadioButtonSelection(); if (position == 0) { makePrevousButtonUnclickable(); } else { makePrevousButtonClickable(); } mNextButton.setText(getResources().getString(R.string.next_button)); Log.d(TAG, "int pos : " + position); goToSelectedQuestion(position); ad.dismiss(); } }); }