Android快速开发框架 roboguice

时间:2022-04-26
本文章向大家介绍Android快速开发框架 roboguice,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

我记得推过一篇文章也是快速开发框架的,今天再来一篇!

1、roboguice 效果


图文无关

2、roboguice 说明


roboguice 是一个不错的开源快速开发框架,采用注解等简洁化代码。

温馨提示:学习无止境,休息更重要。会休息的人才会学习。

3、roboguice 使用


例子列表:

使用框架前

使用框架后

//使用框架前
class AndroidWay extends Activity {
      TextView name;
      ImageView thumbnail;
      LocationManager loc;
      Drawable icon;
      String myName;


      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          name      = (TextView) findViewById(R.id.name);
          thumbnail = (ImageView) findViewById(R.id.thumbnail);
          loc       = (LocationManager) getSystemService(Activity.LOCATION_SERVICE);
          icon      = getResources().getDrawable(R.drawable.icon);
          myName    = getString(R.string.app_name);
          name.setText( "Hello, " + myName );
      }
  }






//使用框架后
@ContentView(R.layout.main)
class RoboWay extends RoboActivity {


@InjectView(R.id.name) TextView name;
@InjectView(R.id.thumbnail) ImageView thumbnail;
@InjectResource(R.drawable.icon) Drawable icon;
@InjectResource(R.string.app_name) String myName;
@Inject LocationManager loc;


public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
name.setText( "Hello, " + myName );
}
}