手机通讯录

原创 2012年03月22日 10:55:52

手机主界面的UI 01





AddNewActivity

public class AddNewActivity extends Activity {
	ImageButton btn_img;
	AlertDialog imageChooseDialog;
	Gallery gallery; 
	ImageSwitcher is;
	int imagePosition;  
	
	//以下在  自定义方法 inint() 中初始化
	EditText et_name;
	EditText et_mobilePhone;
	EditText et_familyPhone;
	EditText et_officePhone;
	EditText et_position;
	EditText et_company;
	EditText et_address;
	EditText et_zipCode;
	EditText et_email;
	EditText et_otherContact;
	EditText et_remark;
	
	Button btn_save;
	Button btn_return;

	private int[] images = {R.drawable.icon,R.drawable.image1,R.drawable.image2,R.drawable.image3,R.drawable.image4,
							R.drawable.image5,R.drawable.image6,R.drawable.image7,R.drawable.image8,
							R.drawable.image9,R.drawable.image10,R.drawable.image11,R.drawable.image12,
							R.drawable.image13,R.drawable.image14,R.drawable.image15,R.drawable.image16,
							R.drawable.image17,R.drawable.image18,R.drawable.image19,R.drawable.image20,
							R.drawable.image21,R.drawable.image22,R.drawable.image23,R.drawable.image24,};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.addnew);
        
        initWidget();
        
        btn_save.setOnClickListener(new OnClickListener() {
        	
        	public void onClick(View v) {
        		String name = et_name.getText().toString();
        		if(name.equals("")) {
        			Toast.makeText(AddNewActivity.this, "姓名不能为空",Toast.LENGTH_LONG).show();
        			return;
        		}
        		String mobilePhone = et_mobilePhone.getText().toString();
				String officePhone = et_officePhone.getText().toString();
				String familyPhone = et_familyPhone.getText().toString();
				String position = et_position.getText().toString();
				String company = et_company.getText().toString();
				String address = et_address.getText().toString();
				String email = et_email.getText().toString();
				String zipCode = et_zipCode.getText().toString();
				String otherContact = et_otherContact.getText().toString();
				String remark = et_remark.getText().toString();
				int imageId = images[imagePosition];
				
				User user = new User();
				user.address = address;
				user.company = company;
				user.email = email;
				user.familyPhone = familyPhone;
				user.imageId = imageId;
				user.mobilePhone = mobilePhone;
				user.officePhone = officePhone;
				user.name = name;
				user.otherContact = otherContact;
				user.position = position;
				user.remark = remark;
				user.zipCode = zipCode;
        			
        			
        			//save user to  database 保存到数据库里面去 
        			long success = DBHelper.getInstance(AddNewActivity.this).save(user);
        			if(success != -1){
        				Toast.makeText(AddNewActivity.this,"添加成功",Toast.LENGTH_LONG).show();        				
        				//1代表 增加用户成功,返回到主页面
        				setResult(1);
        				finish();
        			}else{
        				Toast.makeText(AddNewActivity.this, "添加失败,请重新添加", Toast.LENGTH_LONG).show();
        				//2代表 代表增加用户失败,返回主页面
        				setResult(2);
        				finish();
        			}
        }});
        
        btn_img = (ImageButton)this.findViewById(R.id.btn_img);
        btn_img.setOnClickListener(new OnClickListener(){
        	
        	public void onClick(View v){
        		initImageChooseDialog();
        		imageChooseDialog.show();        		
        	} });
        btn_return.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				setResult(2);  
				finish();				
			}});
    }
    
    public void initWidget(){
    	et_name = (EditText) this.findViewById(R.id.et_name);
		et_mobilePhone = (EditText) this.findViewById(R.id.et_mobilephone);
		et_familyPhone = (EditText) this.findViewById(R.id.et_familyphone);
		et_officePhone = (EditText) this.findViewById(R.id.et_officephone);
		et_position = (EditText) this.findViewById(R.id.et_position);
		et_company = (EditText) this.findViewById(R.id.et_company);
		et_address = (EditText) this.findViewById(R.id.et_address);
		et_zipCode = (EditText) this.findViewById(R.id.et_zipcode);
		et_email = (EditText) this.findViewById(R.id.et_email);
		et_otherContact = (EditText) this.findViewById(R.id.et_other);
		et_remark = (EditText) this.findViewById(R.id.et_remark);
		
		btn_save = (Button) this.findViewById(R.id.btn_save);
		btn_return = (Button) this.findViewById(R.id.btn_return);   
    }
  
	private void initImageChooseDialog() {
		 AlertDialog.Builder builder = new AlertDialog.Builder(this);
		 builder.setTitle("请选择图像");
		 builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				btn_img.setImageResource(images[imagePosition%images.length]);
				
			}
		});
		 builder.setNegativeButton("取消", new DialogInterface.OnClickListener(){
			 public void onClick(DialogInterface dialog, int which){
				 
			 }
		 });
		 
		 LayoutInflater inflater = LayoutInflater.from(this);
		 View view = inflater.inflate(R.layout.imageswitch, null);
		 gallery = (Gallery)view.findViewById(R.id.img_gallery);
		 gallery.setAdapter(new ImageAdapter(this));
		 gallery.setSelection(images.length/2);
		 
		 is = (ImageSwitcher)view.findViewById(R.id.image_switcher);
		 //选择事件成功选择
		 gallery.setOnItemSelectedListener(new OnItemSelectedListener(){
				
			 public void onItemSelected(AdapterView<?> parent, View view,
					 int position, long id){
				 imagePosition = position;
				 is.setImageResource(images[position%images.length]);	 
			 }

			@Override
			public void onNothingSelected(AdapterView<?> parent) {
				// TODO Auto-generated method stub				
			}
		 });
		 
		 is.setFactory(new MyViewFactory(this));
		 builder.setView(view);
		 imageChooseDialog = builder.create();
	}
	
	//ImageAdapter图像适配器 ---内部类
	class ImageAdapter extends BaseAdapter{
		private Context context;
		
		public ImageAdapter(Context context){
			this.context = context;
		}
		
		public int getCount(){
			return Integer.MAX_VALUE;
		}
		
		public Object getItem(int position){
			return null;
		}
		
		public  long getItemId(int position){
			return 0;
		}
				
		public View getView(int position, View convertView, ViewGroup parent){
			ImageView iv = new ImageView(context);
			iv.setImageResource(images[position%images.length]);
			iv.setAdjustViewBounds(true);
			iv.setLayoutParams(new Gallery.LayoutParams(80,80));   //选择头像图标  大小
			iv.setPadding(15,10,15,10);		//图片框之间的间距
			return iv;
		}
		
	}
	
	class MyViewFactory implements ViewFactory{
		
		private  Context context;
		
		public MyViewFactory(Context context){
			this.context = context;
		}
		
		public View makeView(){
			ImageView iv = new ImageView(context);
			iv.setLayoutParams(new ImageSwitcher.LayoutParams(90,90));  //选定框中 选定头像
			return iv;
		}
	}
}
























16_1
















版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

Android 手机通讯录的实现源码

Android 手机通讯录的实现源码 效果图 源码下载地址:http://download.csdn.net/detail/pcaxb/9114685 核心代码: package com....
  • pcaxb
  • pcaxb
  • 2015-09-17 15:23
  • 1421

【Android】获取手机通讯录中的联系人信息

1.手机中的联系人信息是经常用到的一个功能,下面这段代码

ContentProvider与隐式Intent获取手机联系人通讯录信息或电话的方法

ContentProvider与隐式Intent获取手机联系人通讯录信息或电话的方法

手机通讯录恢复

前段时间我哥备份手机通讯录备份的是xls表格格式(我也不知道为什么要导出成这样的,,,汗死),然后现在导入不进去了,用各种软件都是错误。我导出为vcard的(后缀是vcf),以文本格式打开看了下,发现...

andorid调用手机通讯录中的联系人

为了实现一个类似通讯录的功能,所以下了下面这个model,来实现得到手机通讯录的联系人 代码如下: public class ContactModel { public void get...

手机通讯录的逻辑

转自:http://www.williamlong.info/archives/2651.html 所有的产品都要回归一个本源,存在的价值!很多产品会改变时代,比如微博、比如LBS服务,其影响正在或者...

ios开发之获得手机通讯录中所有联系人的属性

001 ABAddressBookRef addressBook = ABAddressBookCreate(); 002    ...

获取手机通讯录

在公司里写了一段上传用户通讯录的代码。写下来,以便以后查阅; 获取手机里的通讯录: /** * 获取通讯录 * @param context * @return 返回包含用户名,与...
  • kazeik
  • kazeik
  • 2012-10-11 16:18
  • 1024

android获取手机通讯录联系人

获得手机通讯录联系人信息    /**得到手机通讯录联系人信息**/          private void getPhoneContacts() {       C...

iOS导入手机通讯录

ABAddressBookRef addressBooks = nil;          if ([[UIDevice currentDevice].systemVersion f...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)