1,fastjson
json是种文件交换的协议,中间有人贡献了工具jackjson,fastjson等,我作为一线程序员用工具高效率完成工作。
类似的:http 协议,httpclient 工具,我 使用者。
序列化:
Object o = ...;
@H_404_30@String text = JSON.toJSONString(o);
|
反序列化:
2,BaseActivity
1),很多界面有相似的布局,比如相同的titlebar和footerbar,将相同界面独立出来的BaseActivity。界面性的BaseActivity
public class UiBaseActivity extends Activity implements OnClickListener { private Button pre_page; private Button next_page; private TextView title; private LinearLayout content; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.ui_base); findViewById(); pre_page.setOnClickListener(this); next_page.setOnClickListener(this); } private void findViewById() { pre_page = (Button) findViewById(R.id.pre_page); next_page = (Button) findViewById(R.id.next_page); title = (TextView) findViewById(R.id.title); content = (LinearLayout) findViewById(R.id.content); } @Override public void onClick(View v) { if(v.getId() == R.id.pre_page){ Toast.makeText(this,"pre_page",0).show(); }else if(v.getId() == R.id.next_page){ Toast.makeText(this,"next_page",0).show(); } } public void setTitleBarTitle(String title){ if(this.title != null){ this.title.setText(title); } } public void setEmbededContentView(int childViewId){ LinearLayout llContent = (LinearLayout) findViewById(R.id.content); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflater.inflate(childViewId,null); llContent.addView(v); } }
ui_base.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:id="@+id/pre_page" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:text="前一页"/> <Button android:id="@+id/next_page" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:text="后一页"/> <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:text="default" /> <LinearLayout android:id="@+id/content" android:layout_below="@+id/pre_page" android:layout_width="fill_parent" android:layout_height="fill_parent"></LinearLayout> </RelativeLayout>2)还有一种那就是功能性的BaseActivity,更多时候可能是混合着用