码迷,mamicode.com
首页 > 移动开发 > 详细

android xml的生成与解析

时间:2016-07-20 19:18:17      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:

Main java

package com.itheima.xml;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

import com.itheima.xml.util.SmsUtils;

public class MainActivity extends Activity implements OnClickListener {

    private Context mContext;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mContext = this;
        //1.找到控件
        Button bt_backup = (Button) findViewById(R.id.bt_backup);
        Button bt_restore = (Button) findViewById(R.id.bt_restore);
        //2.设置点击事件
        bt_backup.setOnClickListener(this);
        bt_restore.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.bt_backup:
            if(SmsUtils.backupSms_android(mContext)){
                Toast.makeText(mContext, "短信备份成功", Toast.LENGTH_SHORT).show();
            }else{
                Toast.makeText(mContext, "短信备份失败", Toast.LENGTH_SHORT).show();
            }
            break;
        case R.id.bt_restore:
            int result = SmsUtils.restoreSms(mContext);
            Toast.makeText(mContext, "成功恢复"+result+"条短信", Toast.LENGTH_SHORT).show();
            break;
        default:
            break;
        }
    }


}

 

 

 

 

package com.itheima.xml;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

import com.itheima.xml.util.SmsUtils;

public class MainActivity extends Activity implements OnClickListener {

    private Context mContext;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mContext = this;
        //1.找到控件
        Button bt_backup = (Button) findViewById(R.id.bt_backup);
        Button bt_restore = (Button) findViewById(R.id.bt_restore);
        //2.设置点击事件
        bt_backup.setOnClickListener(this);
        bt_restore.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.bt_backup:
            if(SmsUtils.backupSms_android(mContext)){
                Toast.makeText(mContext, "短信备份成功", Toast.LENGTH_SHORT).show();
            }else{
                Toast.makeText(mContext, "短信备份失败", Toast.LENGTH_SHORT).show();
            }
            break;
        case R.id.bt_restore:
            int result = SmsUtils.restoreSms(mContext);
            Toast.makeText(mContext, "成功恢复"+result+"条短信", Toast.LENGTH_SHORT).show();
            break;
        default:
            break;
        }
    }


}

 

package com.itheima.xml.dao;

import java.util.ArrayList;

import com.itheima.xml.bean.SmsBean;

public class SmsDao {

    //获取短信数据,模拟一些假数据
    public static ArrayList<SmsBean> getAllSms() {
        ArrayList<SmsBean> arrayList = new ArrayList<SmsBean>();
        
        SmsBean smsBean = new SmsBean();
        smsBean.id = 1;
        smsBean.num = "110";
        smsBean.msg = "来警局做个笔录";
        smsBean.date = "2015-08-29";
        arrayList.add(smsBean);
        
        
        SmsBean smsBean1 = new SmsBean();
        smsBean1.id = 2;
        smsBean1.num = "120";
        smsBean1.msg = "最近咋样";
        smsBean1.date = "2015-08-29";
        arrayList.add(smsBean1);
        
        
        SmsBean smsBean2 = new SmsBean();
        smsBean2.id = 3;
        smsBean2.num = "119";
        smsBean2.msg = "火灭了吗";
        smsBean2.date = "2015-08-29";
        arrayList.add(smsBean2);
        
        
        
        return arrayList;
        
    }

}

 

 

package com.itheima.xml.bean;

public class SmsBean {

    public String num ;
    public String msg;
    public String date;
    public int id;
    
    
}

 

android xml的生成与解析

标签:

原文地址:http://www.cnblogs.com/liangqiyuan/p/5689185.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!