Search in sources :

Example 46 with ToggleButton

use of android.widget.ToggleButton in project ExpandTabView by yueyueniao2012.

the class ExpandTabView method setValue.

/**
 * 设置tabitem的个数和初始值
 */
public void setValue(ArrayList<String> textArray, ArrayList<View> viewArray) {
    if (mContext == null) {
        return;
    }
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mTextArray = textArray;
    for (int i = 0; i < viewArray.size(); i++) {
        final RelativeLayout r = new RelativeLayout(mContext);
        int maxHeight = (int) (displayHeight * 0.7);
        RelativeLayout.LayoutParams rl = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, maxHeight);
        rl.leftMargin = 10;
        rl.rightMargin = 10;
        r.addView(viewArray.get(i), rl);
        mViewArray.add(r);
        r.setTag(SMALL);
        ToggleButton tButton = (ToggleButton) inflater.inflate(R.layout.toggle_button, this, false);
        addView(tButton);
        View line = new TextView(mContext);
        line.setBackgroundResource(R.drawable.choosebar_line);
        if (i < viewArray.size() - 1) {
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(2, LinearLayout.LayoutParams.FILL_PARENT);
            addView(line, lp);
        }
        mToggleButton.add(tButton);
        tButton.setTag(i);
        tButton.setText(mTextArray.get(i));
        r.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                onPressBack();
            }
        });
        r.setBackgroundColor(mContext.getResources().getColor(R.color.popup_main_background));
        tButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {
                // initPopupWindow();
                ToggleButton tButton = (ToggleButton) view;
                if (selectedButton != null && selectedButton != tButton) {
                    selectedButton.setChecked(false);
                }
                selectedButton = tButton;
                selectPosition = (Integer) selectedButton.getTag();
                startAnimation();
                if (mOnButtonClickListener != null && tButton.isChecked()) {
                    mOnButtonClickListener.onClick(selectPosition);
                }
            }
        });
    }
}
Also used : ToggleButton(android.widget.ToggleButton) TextView(android.widget.TextView) View(android.view.View) LayoutInflater(android.view.LayoutInflater) RelativeLayout(android.widget.RelativeLayout) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Example 47 with ToggleButton

use of android.widget.ToggleButton in project little-bear-dictionary by daimajia.

the class OfflineListCursorAdapter method bindView.

@Override
public void bindView(View convertView, Context context, Cursor cursor) {
    TextView dictionary_name_textView = (TextView) convertView.findViewById(R.id.item_dictionary_name);
    TextView dictionary_size = (TextView) convertView.findViewById(R.id.item_dictionary_size);
    ToggleButton toggleButton = (ToggleButton) convertView.findViewById(R.id.item_hide);
    Boolean isShow = cursor.getInt(cursor.getColumnIndex("dictionary_show")) == 1 ? true : false;
    toggleButton.setChecked(isShow);
    toggleButton.setContentDescription(cursor.getString(cursor.getColumnIndex("_id")));
    toggleButton.setOnCheckedChangeListener(this);
    dictionary_name_textView.setText(cursor.getString(cursor.getColumnIndex("dictionary_name")));
    dictionary_size.setText(cursor.getString(cursor.getColumnIndex("dictionary_size")));
}
Also used : ToggleButton(android.widget.ToggleButton) TextView(android.widget.TextView)

Example 48 with ToggleButton

use of android.widget.ToggleButton in project butterknife by JakeWharton.

the class OnCheckedChangedTest method argumentCast.

@UiThreadTest
@Test
public void argumentCast() {
    class MyView extends ToggleButton implements ArgumentCast.MyInterface {

        MyView(Context context) {
            super(context);
        }
    }
    View view1 = new MyView(InstrumentationRegistry.getContext());
    view1.setId(1);
    View view2 = new MyView(InstrumentationRegistry.getContext());
    view2.setId(2);
    View view3 = new MyView(InstrumentationRegistry.getContext());
    view3.setId(3);
    ViewGroup tree = new FrameLayout(InstrumentationRegistry.getContext());
    tree.addView(view1);
    tree.addView(view2);
    tree.addView(view3);
    ArgumentCast target = new ArgumentCast();
    ButterKnife.bind(target, tree);
    view1.performClick();
    assertSame(view1, target.last);
    view2.performClick();
    assertSame(view2, target.last);
    view3.performClick();
    assertSame(view3, target.last);
}
Also used : Context(android.content.Context) ToggleButton(android.widget.ToggleButton) ViewGroup(android.view.ViewGroup) FrameLayout(android.widget.FrameLayout) View(android.view.View) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Aggregations

ToggleButton (android.widget.ToggleButton)48 View (android.view.View)21 TextView (android.widget.TextView)21 ImageView (android.widget.ImageView)13 Button (android.widget.Button)11 SeekBar (android.widget.SeekBar)10 CompoundButton (android.widget.CompoundButton)9 AdapterView (android.widget.AdapterView)7 OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)6 ViewGroup (android.view.ViewGroup)5 ListView (android.widget.ListView)4 SuppressLint (android.annotation.SuppressLint)3 CheckBox (android.widget.CheckBox)3 EditText (android.widget.EditText)3 LinearLayout (android.widget.LinearLayout)3 RadioButton (android.widget.RadioButton)3 Context (android.content.Context)2 KeyEvent (android.view.KeyEvent)2 OnClickListener (android.view.View.OnClickListener)2 ArrayAdapter (android.widget.ArrayAdapter)2