Android Studio中 Android butterKnife Zelezny和 Android Parcelable code generator的使用(备忘录)
2015-11-06 11:21
274 查看
Android butterKnife Zelezny和Android Parcelable code generator的介绍与使用
介绍:
Android butterKnife Zelezny是一款注解框架插件,优点是节约开发时间和减少代码量,减少开发是繁琐的开发量,缺点看个人。我认为一种新的工具或框架,凡是在某种业务场景下,利大于弊,那就是值得使用。
具体使用参照
官网介绍:http://jakewharton.github.io/butterknife/
github:https://github.com/JakeWharton/butterknife
Android Parcelable code generator,词穷,暂时想不到如何描述更好,就是一款自动让对象实现Parcelable的插件吧,免得你写重复代码玩意,更快更方便。
使用:
a、首先打开Android Studio
b、然后点击Settings -> Plugins -> Browse repositories -> 搜索Android butterKnife Zelezny -> Install plugin
c、Android Parcelable code generator安装方式同b操作,安装完成重启AS
d、新建项目,具体如何使用,借用一张动态图,不知图作者是谁,先借用啦,有问题请留言。
示例代码:
运行之后的效果:
介绍:
Android butterKnife Zelezny是一款注解框架插件,优点是节约开发时间和减少代码量,减少开发是繁琐的开发量,缺点看个人。我认为一种新的工具或框架,凡是在某种业务场景下,利大于弊,那就是值得使用。
具体使用参照
官网介绍:http://jakewharton.github.io/butterknife/
github:https://github.com/JakeWharton/butterknife
Android Parcelable code generator,词穷,暂时想不到如何描述更好,就是一款自动让对象实现Parcelable的插件吧,免得你写重复代码玩意,更快更方便。
使用:
a、首先打开Android Studio
b、然后点击Settings -> Plugins -> Browse repositories -> 搜索Android butterKnife Zelezny -> Install plugin
c、Android Parcelable code generator安装方式同b操作,安装完成重启AS
d、新建项目,具体如何使用,借用一张动态图,不知图作者是谁,先借用啦,有问题请留言。
示例代码:
布局文件activity_plugin <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="cn.richinfo.thinkdrive.ui.activities.PluginActivity"> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_below="@+id/textView" android:layout_marginTop="45dp" android:text="Test Button" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_alignTop="@+id/button" android:text="New Button" /> </RelativeLayout>
PluginActivity类 import android.content.Intent; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.view.View; import android.widget.Button; import android.widget.TextView; import butterknife.Bind; import butterknife.ButterKnife; import butterknife.OnClick; import butterknife.OnLongClick; import cn.richinfo.thinkdrive.R; import cn.richinfo.thinkdrive.logic.db.model.UserInfo; import cn.richinfo.thinkdrive.logic.model.response.MyInfoDao; public class PluginActivity extends ActionBarActivity { @Bind(R.id.textView) TextView textView; @Bind(R.id.button) Button button; @Bind(R.id.button2) Button button2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_plugin); ButterKnife.bind(this); } @OnClick({R.id.button, R.id.button2}) public void onButtonClick(View v) { switch (v.getId()) { case R.id.button: textView.setText("i am from test button " + "onButtonClick"); redirectToSecondActivity(new MyInfoDao("羊习习", "XX Company")); break; case R.id.button2: textView.setText("i am from new button2 " + "onButtonClick"); break; } } @OnLongClick(R.id.button) public boolean onButtonLongClick(View v) { textView.setText("i am from test button " + "onButtonLongClick"); return true; } private void redirectToSecondActivity(MyInfoDao mUserInfo) { Intent intent = new Intent(PluginActivity.this, SecondActivity.class); //直接通过intent传输实现过Parcelable的对象 intent.putExtra("userinfo", mUserInfo); startActivity(intent); } @Override protected void onDestroy() { super.onDestroy(); ButterKnife.unbind(this); } }
布局文件activity_second <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="cn.richinfo.thinkdrive.ui.activities.SecondActivity"> <TextView android:id="@+id/tv_content" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RelativeLayout>
SecondActivity类 import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.widget.TextView; import butterknife.Bind; import butterknife.ButterKnife; import cn.richinfo.thinkdrive.R; public class SecondActivity extends ActionBarActivity { @Bind(R.id.tv_content) TextView tvContent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); ButterKnife.bind(this); tvContent.setText(getIntent().getExtras().getParcelable("userinfo").toString()); } }
MyInfoDao 类 import android.os.Parcel; import android.os.Parcelable; /** * Created by Administrator on 2015/11/6. */ public class MyInfoDao implements Parcelable { private String name; private String company; public MyInfoDao(String name, String company) { this.name = name; this.company = company; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getCompany() { return company; } public void setCompany(String company) { this.company = company; } @Override public String toString() { return "[" + getName() + " " + getCompany() + "]"; } @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeString(this.name); dest.writeString(this.company); } /** * 以下都是通过Android Parcelable code generator自动生成 */ public MyInfoDao() { } protected MyInfoDao(Parcel in) { this.name = in.readString(); this.company = in.readString(); } public static final Parcelable.Creator<MyInfoDao> CREATOR = new Parcelable.Creator<MyInfoDao>() { public MyInfoDao createFromParcel(Parcel source) { return new MyInfoDao(source); } public MyInfoDao[] newArray(int size) { return new MyInfoDao[size]; } }; }
运行之后的效果:
相关文章推荐
- 如何成为一名专家级的开发人员
- 插件管理框架 for Delphi(一)
- 使用CSS框架布局的缺点和优点小结
- 列举PHP的Yii 2框架的开发优势
- .NET微信公众号开发之公众号消息处理
- Windows窗体的.Net框架绘图技术实现方法
- 浅谈JavaScript 框架分类
- 轻量级javascript 框架Backbone使用指南
- javascript实现框架高度随内容改变的方法
- 使用nodejs开发cli项目实例
- JS刷新框架外页面七种实现代码
- 超赞的动手创建JavaScript框架的详细教程
- nodejs开发微博实例
- Egret引擎开发指南之创建项目
- 简单介绍不用库(框架)自己写ajax
- asp.net4.0框架下验证机制失效的原因及处理办法
- 插件管理框架 for Delphi(二)
- Android开发自学笔记(二):工程文件剖析
- 零基础学习AJAX之AJAX框架
- Ajax 框架学习笔记