2013.9.17 fastjson,BaseActivity

前端之家收集整理的这篇文章主要介绍了2013.9.17 fastjson,BaseActivity前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1,fastjson

json是种文件交换的协议,中间有人贡献了工具jackjson,fastjson等,我作为一线程序员用工具高效率完成工作。

类似的:http 协议,httpclient 工具,我 使用者。

序列化:

Object o = ...;
String text = JSON.toJSONString(o);

反序列化:

String text = ...; // 例如 {"name":"张老头","age":66}
JSONObject json = JSON.parSEObject(text);

Object o = ....;
JSONObject json = (JSONObject) JSON.toJSON(o);


2,BaseActivity

1),很多界面有相似的布局,比如相同的titlebar和footerbar,将相同界面独立出来的BaseActivity。界面性的BaseActivity

  1. public class UiBaseActivity extends Activity implements OnClickListener {
  2. private Button pre_page;
  3. private Button next_page;
  4. private TextView title;
  5. private LinearLayout content;
  6.  
  7. @Override
  8. protected void onCreate(Bundle savedInstanceState) {
  9. super.onCreate(savedInstanceState);
  10. setContentView(R.layout.ui_base);
  11. findViewById();
  12. pre_page.setOnClickListener(this);
  13. next_page.setOnClickListener(this);
  14. }
  15.  
  16. private void findViewById() {
  17. pre_page = (Button) findViewById(R.id.pre_page);
  18. next_page = (Button) findViewById(R.id.next_page);
  19. title = (TextView) findViewById(R.id.title);
  20. content = (LinearLayout) findViewById(R.id.content);
  21. }
  22.  
  23. @Override
  24. public void onClick(View v) {
  25. if(v.getId() == R.id.pre_page){
  26. Toast.makeText(this,"pre_page",0).show();
  27. }else if(v.getId() == R.id.next_page){
  28. Toast.makeText(this,"next_page",0).show();
  29. }
  30. }
  31. public void setTitleBarTitle(String title){
  32. if(this.title != null){
  33. this.title.setText(title);
  34. }
  35. }
  36. public void setEmbededContentView(int childViewId){
  37. LinearLayout llContent = (LinearLayout) findViewById(R.id.content);
  38. LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  39. View v = inflater.inflate(childViewId,null);
  40. llContent.addView(v);
  41. }
  42. }

ui_base.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical" >
  6. <Button
  7. android:id="@+id/pre_page"
  8. android:layout_width="wrap_content"
  9. android:layout_height="wrap_content"
  10. android:layout_alignParentLeft="true"
  11. android:text="前一页"/>
  12. <Button
  13. android:id="@+id/next_page"
  14. android:layout_width="wrap_content"
  15. android:layout_height="wrap_content"
  16. android:layout_alignParentRight="true"
  17. android:text="后一页"/>
  18. <TextView
  19. android:id="@+id/title"
  20. android:layout_width="wrap_content"
  21. android:layout_height="wrap_content"
  22. android:layout_centerHorizontal="true"
  23. android:text="default" />
  24. <LinearLayout
  25. android:id="@+id/content"
  26. android:layout_below="@+id/pre_page"
  27. android:layout_width="fill_parent"
  28. android:layout_height="fill_parent"></LinearLayout>
  29.  
  30. </RelativeLayout>
2)还有一种那就是功能性的BaseActivity,更多时候可能是混合着用

猜你在找的Json相关文章