Android Open Source - material-dialogs Button Item Adapter






From Project

Back to project page material-dialogs.

License

The source code is released under:

MIT License

If you think the Android project material-dialogs listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.afollestad.materialdialogssample;
//from   ww w. j  ava  2  s  .  co  m
import android.annotation.SuppressLint;
import android.content.Context;
import android.support.annotation.ArrayRes;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Simple adapter example for custom items in the dialog
 */
class ButtonItemAdapter extends BaseAdapter implements View.OnClickListener {

    private Toast mToast;
    private final Context mContext;
    private final CharSequence[] mItems;

    public ButtonItemAdapter(Context context, @ArrayRes int arrayResId) {
        this(context, context.getResources().getTextArray(arrayResId));
    }

    private ButtonItemAdapter(Context context, CharSequence[] items) {
        this.mContext = context;
        this.mItems = items;
    }

    @Override
    public int getCount() {
        return mItems.length;
    }

    @Override
    public CharSequence getItem(int position) {
        return mItems[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @SuppressLint("ViewHolder")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = View.inflate(mContext, R.layout.dialog_customlistitem, null);
        ((TextView) view.findViewById(R.id.title)).setText(mItems[position] + " (" + position + ")");
        Button button = (Button) view.findViewById(R.id.button);
        button.setTag(position);
        button.setOnClickListener(this);
        return view;
    }

    @Override
    public void onClick(View v) {
        Integer index = (Integer) v.getTag();
        if (mToast != null) mToast.cancel();
        mToast = Toast.makeText(mContext, "Clicked button " + index, Toast.LENGTH_SHORT);
        mToast.show();
    }
}




Java Source Code List

com.afollestad.materialdialogs.ApplicationTest.java
com.afollestad.materialdialogs.DialogAction.java
com.afollestad.materialdialogs.GravityEnum.java
com.afollestad.materialdialogs.MaterialDialogCompat.java
com.afollestad.materialdialogs.MaterialDialog.java
com.afollestad.materialdialogs.ThemeSingleton.java
com.afollestad.materialdialogs.Theme.java
com.afollestad.materialdialogs.base.DialogBase.java
com.afollestad.materialdialogs.util.DialogUtils.java
com.afollestad.materialdialogs.util.RecyclerUtil.java
com.afollestad.materialdialogs.util.TypefaceHelper.java
com.afollestad.materialdialogssample.ApplicationTest.java
com.afollestad.materialdialogssample.ButtonItemAdapter.java
com.afollestad.materialdialogssample.ColorChooserDialog.java
com.afollestad.materialdialogssample.FolderSelectorDialog.java
com.afollestad.materialdialogssample.MainActivity.java