Example usage for android.widget GridView setAdapter

List of usage examples for android.widget GridView setAdapter

Introduction

In this page you can find the example usage for android.widget GridView setAdapter.

Prototype

@Override
public void setAdapter(ListAdapter adapter) 

Source Link

Document

Sets the data behind this GridView.

Usage

From source file:com.nnm.smsviet.MessageListActivity.java

public void initDialog() {
    this.emo_dialog = new Dialog(MessageListActivity.this);
    // dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.emo_dialog.setTitle("Text Emoticons");
    this.emo_dialog.setCancelable(true);
    this.emo_dialog.setContentView(R.layout.emo_girdview);
    GridView gridview = (GridView) this.emo_dialog.findViewById(R.id.gridview);
    gridview.setAdapter(new EmoAdapter(this));
    this.emo_dialog.setCanceledOnTouchOutside(true);
    gridview.setOnItemClickListener(new OnItemClickListener() {

        @Override/*ww w.  j av a  2 s  .c om*/
        public void onItemClick(final AdapterView<?> arg0, final View arg1, final int arg2, final long arg3) {
            if (MessageListActivity.this.etText.getText().toString().endsWith(" ")) {
                MessageListActivity.this.etText.append(emo[arg2]);
            } else {
                MessageListActivity.this.etText.append(" " + emo[arg2]);
            }
            MessageListActivity.this.emo_dialog.cancel();
        }
    });
}

From source file:com.lm.im_huanxin.emoji.EmojiPageFragment.java

protected void initWidget(View rootView) {
    mPagerFace = (ViewPager) rootView.findViewById(R.id.frag_pager_face);
    pagePointLayout = (LinearLayout) rootView.findViewById(R.id.frag_point);

    int total = datas.size();
    int pages = total / ITEM_PAGE_COUNT + (total % ITEM_PAGE_COUNT == 0 ? 0 : 1);

    allPageViews = new GridView[pages];
    pointViews = new RadioButton[pages];

    for (int x = 0; x < pages; x++) {
        int start = x * ITEM_PAGE_COUNT;
        int end = (start + ITEM_PAGE_COUNT) > total ? total : (start + ITEM_PAGE_COUNT);
        final List<Emojicon> itemDatas = datas.subList(start, end);
        GridView view = new GridView(aty);
        EmojiAdapter faceAdapter = new EmojiAdapter(view, itemDatas);

        view.setNumColumns(7);/*from w ww  . j  a va 2s.  c o  m*/
        view.setHorizontalSpacing(1);
        view.setVerticalSpacing(1);
        view.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
        view.setCacheColorHint(0);
        view.setPadding(2, 0, 2, 0);
        view.setBackgroundResource(android.R.color.transparent);
        view.setSelector(android.R.color.transparent);
        view.setVerticalScrollBarEnabled(false);
        view.setGravity(Gravity.CENTER);
        view.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
                FrameLayout.LayoutParams.WRAP_CONTENT));
        view.setAdapter(faceAdapter);

        view.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (listener != null) {
                    Emojicon emoji = itemDatas.get(position);
                    if (DisplayRules.isDeleteEmojicon(emoji)) {
                        listener.selectedBackSpace(emoji);
                    } else {
                        listener.selectedEmoji(emoji);
                    }
                }
            }
        });
        allPageViews[x] = view;

        RadioButton tip = new RadioButton(aty);
        tip.setBackgroundResource(R.drawable.selector_bg_tip);
        RadioGroup.LayoutParams layoutParams = new RadioGroup.LayoutParams(8, 8);
        layoutParams.leftMargin = 10;
        pagePointLayout.addView(tip, layoutParams);
        if (x == 0) {
            tip.setChecked(true);
        }
        pointViews[x] = tip;
    }

    PagerAdapter facePagerAdapter = new FacePagerAdapter(allPageViews);
    mPagerFace.setAdapter(facePagerAdapter);
    mPagerFace.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int index) {
            pointViews[index].setChecked(true);
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }
    });
}

From source file:com.app.sample.chatting.data.emoji.EmojiPageFragment.java

@Override
protected void initWidget(View rootView) {
    super.initWidget(rootView);
    mPagerFace = (ViewPager) rootView.findViewById(R.id.frag_pager_face);
    pagePointLayout = (LinearLayout) rootView.findViewById(R.id.frag_point);

    int total = datas.size();
    int pages = total / ITEM_PAGE_COUNT + (total % ITEM_PAGE_COUNT == 0 ? 0 : 1);

    allPageViews = new GridView[pages];
    pointViews = new RadioButton[pages];

    for (int x = 0; x < pages; x++) {
        int start = x * ITEM_PAGE_COUNT;
        int end = (start + ITEM_PAGE_COUNT) > total ? total : (start + ITEM_PAGE_COUNT);
        final List<Emojicon> itemDatas = datas.subList(start, end);
        GridView view = new GridView(aty);
        EmojiAdapter faceAdapter = new EmojiAdapter(view, itemDatas);

        view.setNumColumns(7);/*  w  w  w.  ja va  2s.  c  o m*/
        view.setHorizontalSpacing(1);
        view.setVerticalSpacing(1);
        view.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
        view.setCacheColorHint(0);
        view.setPadding(2, 0, 2, 0);
        view.setBackgroundResource(android.R.color.transparent);
        view.setSelector(android.R.color.transparent);
        view.setVerticalScrollBarEnabled(false);
        view.setGravity(Gravity.CENTER);
        view.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
                FrameLayout.LayoutParams.WRAP_CONTENT));
        view.setAdapter(faceAdapter);

        view.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (listener != null) {
                    Emojicon emoji = itemDatas.get(position);
                    if (DisplayRules.isDeleteEmojicon(emoji)) {
                        listener.selectedBackSpace(emoji);
                    } else {
                        listener.selectedEmoji(emoji);
                    }
                }
            }
        });
        allPageViews[x] = view;

        RadioButton tip = new RadioButton(aty);
        tip.setBackgroundResource(R.drawable.selector_bg_tip);
        RadioGroup.LayoutParams layoutParams = new RadioGroup.LayoutParams(8, 8);
        layoutParams.leftMargin = 10;
        pagePointLayout.addView(tip, layoutParams);
        if (x == 0) {
            tip.setChecked(true);
        }
        pointViews[x] = tip;
    }

    PagerAdapter facePagerAdapter = new FacePagerAdapter(allPageViews);
    mPagerFace.setAdapter(facePagerAdapter);
    mPagerFace.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int index) {
            pointViews[index].setChecked(true);
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }
    });
}

From source file:io.github.rockerhieu.emojicon.EmojiconGridFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    GridView gridView = (GridView) view.findViewById(R.id.Emoji_GridView);
    Bundle bundle = getArguments();/*from  www  .j  av a  2 s.c om*/
    if (bundle == null) {
        mEmojiconType = Emojicon.TYPE_UNDEFINED;
        mEmojicons = People.DATA;
        mUseSystemDefault = false;
    } else {
        //noinspection WrongConstant
        mEmojiconType = bundle.getInt(ARG_EMOJICON_TYPE);
        if (mEmojiconType == Emojicon.TYPE_UNDEFINED) {
            Parcelable[] parcels = bundle.getParcelableArray(ARG_EMOJICONS);
            mEmojicons = new Emojicon[parcels.length];
            for (int i = 0; i < parcels.length; i++) {
                mEmojicons[i] = (Emojicon) parcels[i];
            }
        } else {
            mEmojicons = Emojicon.getEmojicons(mEmojiconType);
        }
        mUseSystemDefault = bundle.getBoolean(ARG_USE_SYSTEM_DEFAULTS);
    }
    gridView.setAdapter(new EmojiAdapter(view.getContext(), mEmojicons, mUseSystemDefault));
    gridView.setOnItemClickListener(this);
}

From source file:com.shoutin.emojicons.EmojiconGridFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    GridView gridView = (GridView) view.findViewById(R.id.Emoji_GridView);
    Bundle bundle = getArguments();/*from  w ww.  j  a  v  a2s  .com*/
    if (bundle == null) {
        mEmojiconType = Emojicon.TYPE_UNDEFINED;
        mEmojicons = People.DATA;
        mUseSystemDefault = false;
    } else {
        //noinspection WrongConstant
        mEmojiconType = bundle.getInt(ARG_EMOJICON_TYPE);
        if (mEmojiconType == Emojicon.TYPE_UNDEFINED) {
            Parcelable[] parcels = bundle.getParcelableArray(ARG_EMOJICONS);
            mEmojicons = new Emojicon[parcels.length];
            for (int i = 0; i < parcels.length; i++) {
                mEmojicons[i] = (Emojicon) parcels[i];
            }
        } else {
            mEmojicons = Emojicon.getEmojicons(mEmojiconType);
        }
        mUseSystemDefault = bundle.getBoolean(ARG_USE_SYSTEM_DEFAULTS);
    }
    gridView.setAdapter(new EmojiconAdapter(view.getContext(), mEmojicons, mUseSystemDefault));
    gridView.setOnItemClickListener(this);
}

From source file:com.abc.driver.TruckActivity.java

public void chooseTruckWeight(View v) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    GridView gridView1 = new GridView(this);
    gridView1.setNumColumns(3);/*from ww w  .j  a v  a2 s . com*/
    SimpleAdapter adapter = new SimpleAdapter(this, mTruckWeightList, R.layout.truck_weight_griditem,
            new String[] { "TITLE", "TWEIGHT" }, new int[] { R.id.griditem_title, R.id.griditem_weight, });

    gridView1.setAdapter(adapter);
    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) {
            mTWtv.setText(((TextView) view.findViewById(R.id.griditem_title)).getText());
            mTruckWeight = ((TextView) view.findViewById(R.id.griditem_weight)).getText().toString();
            mUpdateTruckTask = new UpdateTruckTask();
            mUpdateTruckTask.execute("" + app.getUser().getMyTruck().getTruckId(),
                    "" + app.getUser().getMyTruck().getTypeId(), "" + app.getUser().getMyTruck().getLengthId(),
                    mTruckWeight, "" + app.getUser().getMyTruck().getStatusId(), "" + app.getUser().getId());

            dialog.dismiss();
        }
    });
    dialog.show();
}

From source file:com.abc.driver.TruckActivity.java

public void chooseTruckLength(View v) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    GridView gridView1 = new GridView(this);
    gridView1.setNumColumns(3);/*from w ww.jav a 2  s  .  c  o m*/
    // (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);
    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();
            mUpdateTruckTask = new UpdateTruckTask();
            mUpdateTruckTask.execute("" + app.getUser().getMyTruck().getTruckId(),
                    "" + app.getUser().getMyTruck().getTypeId(), mTruckLength,
                    "" + app.getUser().getMyTruck().getWeightId(),
                    "" + app.getUser().getMyTruck().getStatusId(), "" + app.getUser().getId());

            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   w  w  w  .ja v a2s.c o  m
    }

    // 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();
        }
    });

}

From source file:com.abc.driver.TruckActivity.java

public void chooseTruckType(View v) {

    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    GridView gridView1 = new GridView(this);
    gridView1.setNumColumns(3);/*from  w  ww  .  j  a v  a2  s.c  om*/
    // (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);
    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();

            mUpdateTruckTask = new UpdateTruckTask();
            mUpdateTruckTask.execute("" + app.getUser().getMyTruck().getTruckId(), mTruckType,
                    "" + app.getUser().getMyTruck().getLengthId(),
                    "" + app.getUser().getMyTruck().getWeightId(),
                    "" + app.getUser().getMyTruck().getStatusId(), "" + app.getUser().getId());
            dialog.dismiss();
        }
    });
    dialog.show();
}

From source file:net.alexjf.tmm.fragments.IconPickerFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (savedInstanceState != null) {
        filter = savedInstanceState.getString(KEY_CURRENTFILTER);
    }/*from w  ww. j a va2s . co  m*/

    View v = inflater.inflate(R.layout.fragment_icon_picker, container, false);
    GridView drawableGrid = (GridView) v.findViewById(R.id.icon_grid);
    List<Integer> drawableIds = new LinkedList<Integer>();

    catAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item,
            android.R.id.text1);
    catAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    categorySpinner = (Spinner) v.findViewById(R.id.iconcat_spinner);
    categorySpinner.setAdapter(catAdapter);
    categorySpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            updateGrid(position);
        }

        ;

        public void onNothingSelected(AdapterView<?> parent) {
        }

        ;
    });

    gridAdapter = new DrawableAdapter(getActivity(), drawableIds);

    drawableGrid.setAdapter(gridAdapter);
    drawableGrid.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Integer drawableId = gridAdapter.getItem(position);
            String drawableName = getResources().getResourceEntryName(drawableId);
            dismiss();

            if (listener != null) {
                listener.onIconPicked(drawableId, drawableName);
            } else {
                Log.d("TMM", "Icon selected but listener null");
            }
        }
    });

    updateIcons();
    updateSpinner();
    updateGrid(categorySpinner.getSelectedItemPosition());
    return v;
}