android.widget.Button.getId()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(237)

本文整理了Java中android.widget.Button.getId()方法的一些代码示例,展示了Button.getId()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Button.getId()方法的具体详情如下:
包路径:android.widget.Button
类名称:Button
方法名:getId

Button.getId介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
Button button1;
button1.setLayoutParams(params);

params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.RIGHT_OF, button1.getId());
Button button2;
button2.setLayoutParams(params);

代码示例来源:origin: yipianfengye/android-zxingLibrary

/**
 * 初始化组件
 */
private void initView() {
  button1 = (Button) findViewById(R.id.button1);
  button2 = (Button) findViewById(R.id.button2);
  button3 = (Button) findViewById(R.id.button3);
  button4 = (Button) findViewById(R.id.button4);
  /**
   * 打开默认二维码扫描界面
   *
   * 打开系统图片选择界面
   *
   * 定制化显示扫描界面
   *
   * 测试生成二维码图片
   */
  button1.setOnClickListener(new ButtonOnClickListener(button1.getId()));
  button2.setOnClickListener(new ButtonOnClickListener(button2.getId()));
  button3.setOnClickListener(new ButtonOnClickListener(button3.getId()));
  button4.setOnClickListener(new ButtonOnClickListener(button4.getId()));
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

@Override
public void onClick(View v) {
  if (v.getId() == btnAlbumSelected.getId()) {
    if (folderPopupWindow == null) {
      WindowManager wm = getActivity().getWindowManager();
      int width = wm.getDefaultDisplay().getWidth();
      createPopupFolderList(width / 3 * 2, width / 3 * 2);
    }
    if (folderPopupWindow.isShowing()) {
      folderPopupWindow.dismiss();
    } else {
      folderPopupWindow.show();
      int index = folderListAdapter.getSelectIndex();
      index = index == 0 ? index : index - 1;
      folderPopupWindow.getListView().setSelection(index);
    }
  }
}

代码示例来源:origin: leveychen/RxBanner

private float getValue(Button btn) {
  return optionalValue.get(btn.getId())[2];
}

代码示例来源:origin: bigeyechou/Rxjava2Retrofit2NetFrame

@OnClick({R.id.btn1})
public void onClickButton(Button button){
  switch (button.getId()){
    case R.id.btn1:
      Toast.makeText(this,"请配置好相关接口:URLConstant->BASE_URL 和 HttpApi->@GET()",Toast.LENGTH_SHORT);
      // getData();
      break;
    default:
      break;
  }
}

代码示例来源:origin: stackoverflow.com

private HashMap<Integer,Button> btnMap = new HashMap<Integer, Button>();

private void init(){
  Button yourFirstBtn = (Button) findViewById(R.id.yourFirstBtn);
  btnMap.put(yourFirstBtn.getId(), yourFirstBtn);

  for(Button tempBtn: btnMap.values()){
    tempBtn.setOnClickListener(this);
  }
}

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
  Button clickedBtn = btnMap.get(v.getId());
}

代码示例来源:origin: CloudRail/cloudrail-si-android-sdk

@Override
  public void onClick(View v) {
    Button pressed = (Button) v;
    String service = null;
    switch (pressed.getId()) {
      case R.id.amazonButton: service = "amazon"; break;
      case R.id.backblazeButton: service = "backblaze"; break;
      case R.id.googleButton: service = "google"; break;
      case R.id.microsoftButton: service = "microsoft"; break;
      case R.id.rackspaceButton: service = "rackspace"; break;
    }
    mListener.onServiceSelected(service);
  }
};

代码示例来源:origin: antest1/kcanotify

@Override
  public void onClick(View view) {
    if (view.getId() == btnAll.getId()) {
      adapter.selectAll();
    } else if (view.getId() == btnClear.getId()) {
      adapter.unselectAll();
    } else if (view.getId() == btnReverse.getId()) {
      adapter.reverseSelect();
    }
    gv.invalidateViews();
  }
};

代码示例来源:origin: sephiroth74/Android-Exif-Extended

@Override
public void onClick( View v ) {
  final int id = v.getId();
  if( id == button1.getId() ) {
    loadImage();
  }
  else if( id == button2.getId() ) {
    try {
      saveImage();
    } catch( Exception e ) {
      e.printStackTrace();
      Toast.makeText( this, e.getMessage(), Toast.LENGTH_SHORT ).show();
    }
  }
}

代码示例来源:origin: leveychen/RxBanner

private int getConfigGravity(Button btn) {
  return Sys.getGravity(indicesArray.get(btn.getId()));
}

代码示例来源:origin: Yellow5A5/ClearScreenHelper

@Override
  public void onClick(View view) {
    if (view.getId() == mBindBtn.getId()) {
      mClearScreenHelper.bind(mShowTextV);
      mClearScreenHelper.bind(mCenterBtn);
    } else if (view.getId() == mUnBindBtn.getId()) {
      mClearScreenHelper.unbind(mShowTextV);
      mClearScreenHelper.unbind(mCenterBtn);
    } else if (view.getId() == mCenterBtn.getId()) {
      Toast.makeText(SampleFirActivity.this, "Triggers the click event.", Toast.LENGTH_SHORT).show();
    }
  }
};

代码示例来源:origin: stackoverflow.com

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
Button button1;
button1.setLayoutParams(params);

params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.RIGHT_OF, button1.getId());
Button button2;
button2.setLayoutParams(params);

代码示例来源:origin: yuyangXu0222/eBook

private void setCurFlipStyleBtn() {
  Button usedButton = mFlipStyleBtns[mFlipStyle];
  for (Button button : mFlipStyleBtns) {
    GradientDrawable drawable = (GradientDrawable) button.getBackground();
    //设置边框颜色
    if (button.getId() == usedButton.getId()) {
      int strokeColor = mStrokeColors[mTheme]; //被选择button边框颜色由当前theme决定
      drawable.setStroke(5, strokeColor);
    } else {
      drawable.setStroke(5, 0xffc1c0c0);
    }
  }
}

代码示例来源:origin: yuyangXu0222/eBook

private void setCurThemeBtn() {
  Button usedButton = mThemeBtns[mTheme];
  for (int i = 0; i < mThemeBtns.length; i++) {
    // 设置背景填充颜色
    GradientDrawable drawable = (GradientDrawable) mThemeBtns[i].getBackground();
    drawable.setColor(mPopupColors[i]);
    //设置边框颜色
    if (mThemeBtns[i].getId() == usedButton.getId()) {
      int strokeColor = mStrokeColors[i];
      drawable.setStroke(5, strokeColor);
    } else {
      drawable.setStroke(5, mPopupColors[i]);    //未选择button的边框颜色和填充颜色一致
    }
  }
}

代码示例来源:origin: FudanSELab/train-ticket

private void initTimeChooseButton(View view) {
  startTimeBtn = (Button) view.findViewById(R.id.btn_start_time);
  endTimeBtn = (Button) view.findViewById(R.id.btn_end_time);
  addToBtnController(startTimeBtn, endTimeBtn);
  if (null == startTime || null == endTime) {
    startTime = Calendar.getInstance();
    setDateTime(startTime, 0, 0, 0, 0);
    endTime = Calendar.getInstance();
    setDateTime(endTime, 23, 59, 59, 999);
  }
  changeShowTime(R.id.btn_start_time);
  startTimeBtn.setOnClickListener(new TimeChooseListener(startTimeBtn.getId(), startTime));
  endTimeBtn.setOnClickListener(new TimeChooseListener(endTimeBtn.getId(), endTime));
}

代码示例来源:origin: stackoverflow.com

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
Button button1 = (Button)findViewById(R.id.button_operations);
button1.setLayoutParams(params);

//or set its position relative to another button:
params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.RIGHT_OF, button1.getId());
Button button2 = (Button)findViewById(R.id.secondBtn);
button2.setLayoutParams(params);

//or set its margins like this (left, top, right, bottom):
params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(200, 600, 0, 0); //if it is possible don't use hard coded numbers, use parameters based on screen resolution instead
Button button3 = (Button)findViewById(R.id.thirdBtn);
button3.setLayoutParams(params);

代码示例来源:origin: jruesga/rview

@BindingAdapter({"srcDrawable"})
  public static void setButtonResource(Button button, int resource) {
    final Context ctx = button.getContext();
    Drawable drawable = null;
    if (resource != 0) {
      drawable = ContextCompat.getDrawable(ctx, resource);
    }
    button.setCompoundDrawablesWithIntrinsicBounds(
        button.getId() == R.id.page_action_back ? drawable : null,
        null,
        button.getId() == R.id.page_action_forward ? drawable : null,
        null);
  }
}

代码示例来源:origin: zilianliuxue/TBShoppingCart

@Override
  public void onClick(View v) {
    int groupId = v.getId();
    if (groupId == edtor.getId()) {
      if (group.isEdtor()) {
        group.setIsEdtor(false);
      } else {
        group.setIsEdtor(true);
      }
      notifyDataSetChanged();
    }
  }
}

代码示例来源:origin: ravidsrk/android-testing-guide

@Test
public void testAdd() {
  Button addButton = mock(Button.class);
  when(addButton.getId()).thenReturn(R.id.buttonAdd);
  MainActivity activity = activityTestRule.getActivity();
  activity.buttonClicked(addButton);
}

代码示例来源:origin: ravidsrk/android-testing-guide

@Test
  public void testRemove() {
    Button removeButton = mock(Button.class);
    when(removeButton.getId()).thenReturn(R.id.buttonRemove);

    MainActivity activity = activityTestRule.getActivity();
    activity.buttonClicked(removeButton);
  }
}

相关文章

Button类方法