微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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,更多时候可能是混合着用

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐