今天在找资料的时候发现了这个,想法很不错,做个标记吧。
未使用框架时
public class AndroidWay extends Activity
{
private Button btn1;
private Button btn2;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn1 = (Button)this.findViewById(R.id.btn1);
btn2 = (Button)this.findViewById(R.id.btn2);
OnClickListener listener = new OnClickListener(){
@Override
public void onClick(View v)
{
switch(v.getId()){
case R.id.btn1:
//do something
break;
case R.id.btn2:
//do something
break;
}
}};
btn1.setOnClickListener(listener);
btn2.setOnClickListener(listener);
}
}使用框架时public class EasyWay extends EasyActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@OnClick({R.id.btn1, R.id.btn2})
private void doSometing(View v)
{
switch(v.getId()){
case R.id.btn1:
//do something
break;
case R.id.btn2:
//do something
break;
}
}
}http://code.google.com/p/easy-android-utility/