燃烧那滴泪的专栏

学习是一种态度

Butterknife @OnClick绑定多控件id

package com.example.hh;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
import butterknife.Bind;
import butterknife.BindColor;
import butterknife.BindDimen;
import butterknife.BindDrawable;
import butterknife.BindString;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends Activity {

	@Bind(R.id.tv_text1)
	TextView tv_text1;

	@Bind(R.id.tv_text2)
	TextView tv_text2;

	@Bind(R.id.tv_text3)
	TextView tv_text3;

	@Bind(R.id.tv_text4)
	TextView tv_text4;

	

	@SuppressLint("NewApi")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		ButterKnife.bind(MainActivity.this);
		tv_text1.setText("1231");
		tv_text2.setText("1024");
		tv_text3.setText("5454");
		tv_text4.setText("7865");


	}

	// @OnClick(R.id.tv_text1)
	// public void sayHi(TextView button) {
	// button.setText("你按到我了啦!");
	// }
	//
	// @SuppressLint("NewApi")
	// @OnClick(R.id.tv_text2)
	// public void sayHi2(TextView button) {
	// button.setBackground(graphic);
	// }
	//
	// @OnClick(R.id.tv_text3)
	// public void sayHi3(TextView button) {
	// button.setTextColor(red);
	// }
	//
	// @OnClick(R.id.tv_text4)
	// public void sayHi4(TextView button) {
	// button.setTextSize(spacers);
	// }
	@OnClick({ R.id.tv_text1, R.id.tv_text2, R.id.tv_text3, R.id.tv_text4 })
	public void sayHi(TextView button) {
		switch (button.getId()) {
		case R.id.tv_text1:
			button.setText("你按到我了啦1!");
			Toast.makeText(this, "你按到我了啦1!", Toast.LENGTH_SHORT).show();
			break;
		case R.id.tv_text2:
			button.setText("你按到我了啦2!");
			Toast.makeText(this, "你按到我了啦2!", Toast.LENGTH_SHORT).show();
			break;
		case R.id.tv_text3:
			button.setText("你按到我了啦3!");
			Toast.makeText(this, "你按到我了啦3!", Toast.LENGTH_SHORT).show();
			break;
		case R.id.tv_text4:
			button.setText("你按到我了啦4!");
			Toast.makeText(this, "你按到我了啦4!", Toast.LENGTH_SHORT).show();
			break;
		default:
			break;
		}
	}

}

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ZHOU452840622/article/details/51886813
个人分类: android 基础
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭