package simon.contact;
import simon.contact.entity.User;
import simon.contact.entity.UserEditText;
import simon.contact.util.Constant;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Gallery;
import android.widget.ImageButton;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ViewSwitcher.ViewFactory;
public class EditTextActivity extends Activity {
protected UserEditText userEditText = new UserEditText();
protected Button saveButton;
protected Button returnButton;
protected ImageButton imageButton;
protected AlertDialog alertDialog; //选择头像对话框
protected ImageSwitcher imageSwitcher;
protected int imgSelected; //用户选择了哪个头像
protected void initWidget() {
this.userEditText.firstName = (EditText) this.findViewById(R.id.edit_first_name);
this.userEditText.lastName = (EditText) this.findViewById(R.id.edit_last_name);
this.userEditText.company = (EditText) this.findViewById(R.id.edit_company);
this.userEditText.phone = (EditText) this.findViewById(R.id.edit_phone);
this.userEditText.officePhone = (EditText) this.findViewById(R.id.edit_office_phone);
this.userEditText.familyPhone = (EditText) this.findViewById(R.id.edit_family_phone);
this.userEditText.post = (EditText) this.findViewById(R.id.edit_post);
this.userEditText.address = (EditText) this.findViewById(R.id.edit_address);
this.userEditText.email = (EditText) this.findViewById(R.id.edit_mail);
this.userEditText.remark = (EditText) this.findViewById(R.id.edit_remark);
this.imageButton = (ImageButton) super.findViewById(R.id.btn_img);
this.saveButton = (Button) this.findViewById(R.id.btn_save);
this.returnButton = (Button) this.findViewById(R.id.btn_return);
}
protected User buildUserByEditText() {
String firstName = this.userEditText.firstName.getText().toString();
if (firstName == null || TextUtils.isEmpty(firstName)) {
Toast.makeText(this, "姓氏不能为空", Toast.LENGTH_LONG).show();
return null;
}
String lastName = this.userEditText.lastName.getText().toString();
if (lastName == null || TextUtils.isEmpty(lastName)) {
Toast.makeText(this, "名称不能为空", Toast.LENGTH_LONG).show();
return null;
}
User user = new User();
user.setFirstName(firstName);
user.setLastName(lastName);
user.setCompany(this.userEditText.company.getText().toString());
user.setPhone(this.userEditText.phone.getText().toString());
user.setOfficePhone(this.userEditText.officePhone.getText().toString());
user.setFamilyPhone(this.userEditText.familyPhone.getText().toString());
user.setPost(this.userEditText.post.getText().toString());
user.setAddress(this.userEditText.address.getText().toString());
user.setEmail(this.userEditText.email.getText().toString());
user.setRemark(this.userEditText.remark.getText().toString());
user.setImageId(Constant.HEAD_IMGS[imgSelected % Constant.HEAD_IMGS.length]);
return user;
}
/**
* 初始化选择头像对话框
*/
protected void initImgAlertDialog(int selection){
AlertDialog.Builder build = new AlertDialog.Builder(this);
build.setTitle("选择头像图片");
build.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
imageButton.setImageResource(Constant.HEAD_IMGS[imgSelected % Constant.HEAD_IMGS.length]);
}
});
build.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
LayoutInflater layoutInflater = LayoutInflater.from(this);
View view = layoutInflater.inflate(R.layout.imageswitch, null);
Gallery gallery = (Gallery) view.findViewById(R.id.img_gallery);
gallery.setAdapter(new ImageAdapter(this));
gallery.setSelection(selection);
imageSwitcher = (ImageSwitcher) view.findViewById(R.id.img_switcher);
gallery.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long arg3) {
imageSwitcher.setImageResource(Constant.HEAD_IMGS[position % Constant.HEAD_IMGS.length]);
EditTextActivity.this.imgSelected = position;
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
imageSwitcher.setFactory(new MyViewFactory(this));
build.setView(view);
this.alertDialog = build.create();
}
/**
* Gallery适配器
*
* @author think
*
*/
private class ImageAdapter extends BaseAdapter{
private Context context;
public ImageAdapter(Context context) {
this.context = context;
}
/**
* 返回显示图片的个数
*/
public int getCount() {
return Integer.MAX_VALUE;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(this.context);
imageView.setImageResource(Constant.HEAD_IMGS[position % Constant.HEAD_IMGS.length]);
imageView.setAdjustViewBounds(true);
imageView.setLayoutParams(new Gallery.LayoutParams(70, 70)); //设置图片大小
imageView.setPadding(15, 10, 15, 10); //设置图片间隔
return imageView;
}
}
private class MyViewFactory implements ViewFactory{
private Context context;
public MyViewFactory(Context context) {
this.context = context;
}
@Override
public View makeView() {
ImageView imageView = new ImageView(this.context);
imageView.setLayoutParams(new ImageSwitcher.LayoutParams(90, 90));
return imageView;
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
android-contact.zip (89个子文件)
android-contact
AndroidManifest.xml 921B
res
layout
contact_item.xml 764B
user_list_item.xml 3KB
imageswitch.xml 664B
addnew.xml 6KB
detail.xml 6KB
main.xml 1KB
drawable-ldpi
icon.png 2KB
drawable-mdpi
icon.png 3KB
drawable-hdpi
menu_exit.png 2KB
head3.png 41KB
menu_return.png 1KB
head9.png 27KB
head8.png 34KB
controlbar_showtype_list.png 1KB
menu_quit.png 1KB
head12.png 27KB
menu_backup.png 1KB
menu_new_user.png 2KB
menu_search.png 1KB
menu_sum.png 1KB
menu_restore.png 1KB
menu_fresh.png 2KB
head6.png 39KB
exitmenu.png 1KB
menu_delete.png 1KB
head7.png 35KB
head2.png 43KB
head5.png 33KB
head11.png 37KB
channelgallery_bg.png 2KB
head1.png 47KB
head4.png 27KB
icon.png 4KB
head10.png 41KB
head13.png 27KB
head14.png 43KB
backmenu.png 1KB
values
strings.xml 520B
proguard.cfg 1KB
src
simon
contact
EditTextActivity.java 6KB
MainActivity.java 6KB
entity
UserEditText.java 381B
User.java 2KB
DetailActivity.java 5KB
db
DBHelper.java 4KB
util
SqlXmlHandler.java 1KB
Constant.java 1KB
XMLParse.java 829B
AddNewActivity.java 2KB
bin
classes.dex 29KB
simon
contact
EditTextActivity.class 5KB
EditTextActivity$3.class 2KB
entity
User.class 3KB
UserEditText.class 514B
MainActivity$2$1.class 2KB
MainActivity$1.class 2KB
DetailActivity$2.class 828B
DetailActivity$1.class 1KB
db
DBHelper.class 6KB
R.class 496B
MainActivity.class 6KB
util
XMLParse.class 2KB
SqlXmlHandler.class 2KB
Constant.class 1KB
AddNewActivity$2.class 2KB
R$layout.class 548B
R$attr.class 325B
EditTextActivity$ImageAdapter.class 2KB
AddNewActivity$3.class 827B
EditTextActivity$2.class 873B
EditTextActivity$1.class 1KB
DetailActivity$3.class 2KB
R$id.class 1KB
R$string.class 662B
EditTextActivity$MyViewFactory.class 1KB
AddNewActivity$1.class 1KB
DetailActivity$4.class 1KB
AddNewActivity.class 1KB
R$drawable.class 1KB
MainActivity$2.class 3KB
DetailActivity.class 5KB
android-contact.apk 527KB
resources.ap_ 510KB
.classpath 280B
assets
xml
sql.xml 615B
default.properties 362B
.settings
.project 851B
gen
simon
contact
R.java 5KB
共 89 条
- 1
高手名字都很长
- 粉丝: 6
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页