Checkbox ImageView AdapterView 密码显示
来源:互联网 发布:成都海光集成电路 知乎 编辑:程序博客网 时间:2024/06/06 19:44
AdapterView
自定义Adapter
这里用到了MVC设计模式,先新建一个包model,在里面新建一个类Student,主要用于存放数据。
在新建一个包adapter,在里面新建一个类StudentAdapter,主要用于控制。
V表示布局,在layout中。
最后在活动中写入相应代码。
Student类
package com.example.administrator.myweidget.model;/** * Created by Administrator on 2015/8/24. */public class Student { private String name; private String age; private String sex; private String hobby; private int img; public Student(String name,String age,String sex,String hobby,int img){ this.name = name; this.age = age; this.sex = sex; this.hobby = hobby; this.img = img; } public String getName() { return name; } public String getAge() { return age; } public String getSex() { return sex; } public String getHobby() { return hobby; } public int getImg() { return img; } public void setName(String name) { this.name = name; } public void setAge(String age) { this.age = age; } public void setSex(String sex) { this.sex = sex; } public void setHobby(String hobby) { this.hobby = hobby; } public void setImg(int img) { this.img = img; }}
StudentAdapter类
package com.example.administrator.myweidget.adapter;import android.text.Layout;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.ImageView;import android.widget.ListView;import android.widget.TextView;import com.example.administrator.myweidget.R;import com.example.administrator.myweidget.model.Student;import java.util.List;/** * Created by Administrator on 2015/8/24. */public class StudentAdapter extends BaseAdapter{ private List<Student> mData; private LayoutInflater mInflater; public StudentAdapter(LayoutInflater inflater,List<Student> data){ mInflater = inflater; mData = data; } @Override public int getCount() { //得到listview将要显示的数据的条数 return mData.size(); } @Override public Object getItem(int position) { //返回索引 return position; } @Override public long getItemId(int position) { //返回索引 return position; } public View getView(int position,View convertView,ViewGroup parent){ View view = mInflater.inflate(R.layout.simple_adapter,null); Student student = mData.get(position); ImageView imageview = (ImageView) view.findViewById(R.id.image_photo); TextView textview_name = (TextView) view.findViewById(R.id.textview_name); TextView textview_age = (TextView) view.findViewById(R.id.textview_age); TextView textview_sex = (TextView) view.findViewById(R.id.textview_sex); TextView textview_hobby = (TextView) view.findViewById(R.id.textview_hobby); textview_name.setText(student.getName()); textview_age.setText(student.getAge()); textview_sex.setText(student.getSex()); textview_hobby.setText(student.getHobby()); imageview.setImageResource(student.getImg()); return view; }}
布局文件
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="15dp" android:gravity="center_vertical"> <ImageView android:id="@+id/image_photo" android:layout_width="100dp" android:layout_height="100dp" /> <TextView android:id="@+id/textview_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="姓名"/> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:layout_margin="15dp"> <TextView android:id="@+id/textview_age" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="年龄"/> <TextView android:id="@+id/textview_sex" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="性别"/> </LinearLayout> <TextView android:id="@+id/textview_hobby" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="爱好"/></LinearLayout>
Activity中的代码
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list_view); mListView = (ListView) findViewById(R.id.listview); LayoutInflater inflater = getLayoutInflater(); initData(); StudentAdapter adapter = new StudentAdapter(inflater,mData); mListView.setAdapter(adapter); } private void initData() { mData = new ArrayList<>(); Student zhangsan = new Student("李易峰","18","男","爱好打篮球",R.mipmap.li); Student lisi = new Student("Anglebaby","22","女","爱好吃饭",R.mipmap.angle); Student wangwu = new Student("李易峰","20","男","爱好音乐",R.mipmap.li); Student zhaoliu = new Student("唐嫣","21","女","喜欢唱歌",R.mipmap.tang); Student maqi = new Student("杨颖","26","女","素颜",R.mipmap.angle); mData.add(zhangsan); mData.add(lisi); mData.add(wangwu); mData.add(zhaoliu); mData.add(maqi); }
Checkbox
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <RadioGroup android:layout_width="wrap_content" android:layout_height="wrap_content"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" /> <CheckBox android:id="@+id/isshowpassword" android:password="true" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="显示密码"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="爱好"/> <CheckBox android:id="@+id/checkbox_swim" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="游泳"/> <CheckBox android:id="@+id/checkbox_pingpang" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="乒乓球"/> <CheckBox android:id="@+id/checkbox_ride" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="骑车"/> <CheckBox android:id="@+id/checkbox_study" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="游泳"/> </RadioGroup> </LinearLayout>
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mCheckBoxSwim = (CheckBox) findViewById(R.id.checkbox_swim); mCheckBoxPingpang = (CheckBox) findViewById(R.id.checkbox_pingpang); mCheckBoxRide = (CheckBox) findViewById(R.id.checkbox_ride); mCheckBoxStudy = (CheckBox) findViewById(R.id.checkbox_study); mCheckBoxIsShowPassword = (CheckBox) findViewById(R.id.isshowpassword); mCheckBoxIsShowPassword.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { if (isChecked) { mCheckBoxIsShowPassword.setTransformationMethod(null); } else { mCheckBoxIsShowPassword.setTransformationMethod(new PasswordTransformationMethod()); } } });
ImageView
属性有:src 没有被拉伸
background 被拉伸
scaleType :center、fitstart、inside、tint 等
增加透明度 减少透明度
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_image); mAdd = (Button) findViewById(R.id.add); mSub = (Button) findViewById(R.id.sub); mAdd.setOnClickListener(this); mSub.setOnClickListener(this); mImageView = (ImageView) findViewById(R.id.image); mImageView.setImageResource(R.mipmap.angle); }// @Target(Build.VERSION_CODES.JELLY_BEAN) @Override public void onClick(View view) { int code = Build.VERSION.SDK_INT; switch (view.getId()){ case R.id.add: mAlphaCount+=10; Log.d("versioncode","当前版本号"+code); if (code<16){ mImageView.setAlpha(mAlphaCount); }else{ mImageView.setImageAlpha(mAlphaCount); } break; case R.id.sub: mAlphaCount-=10; if (code>16){ mImageView.setAlpha(mAlphaCount); }else{ mImageView.setImageAlpha(mAlphaCount); } break; default: break; } }
<ImageView android:id="@+id/image" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@mipmap/he" /> <Button android:id="@+id/add" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="增加透明度"/> <Button android:id="@+id/sub" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="减少透明度"/>
是否显示密码
public class MainActivity extends Activity { private TextView mTextView; private Button btn; private EditText mEditText; private RadioGroup mRadioGroup; private Button mBtnCommit; private CheckBox mCheckBoxSwim; private CheckBox mCheckBoxPingpang; private CheckBox mCheckBoxRide; private CheckBox mCheckBoxStudy; private CheckBox mCheckBoxIsShowPassword; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mEditText = (EditText) findViewById(R.id.editpassword); mCheckBoxSwim = (CheckBox) findViewById(R.id.checkbox_swim); mCheckBoxPingpang = (CheckBox) findViewById(R.id.checkbox_pingpang); mCheckBoxRide = (CheckBox) findViewById(R.id.checkbox_ride); mCheckBoxStudy = (CheckBox) findViewById(R.id.checkbox_study); mCheckBoxIsShowPassword = (CheckBox) findViewById(R.id.isshowpassword); mCheckBoxIsShowPassword.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { if (isChecked) { mEditText.setTransformationMethod(null); } else { mEditText.setTransformationMethod(new PasswordTransformationMethod()); } } });
<RadioGroup android:layout_width="wrap_content" android:layout_height="wrap_content"> <EditText android:id="@+id/editpassword" android:layout_width="match_parent" android:layout_height="wrap_content" android:password="true"/> <CheckBox android:id="@+id/isshowpassword" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="显示密码"/>
0 0
- Checkbox ImageView AdapterView 密码显示
- 第七周Android(CheckBox /ImageView/ListView/ImageButton/AdapterView)
- 第二十四天 ImageView,AdapterView
- Android CheckBox 选中显示密码小功能
- Android-checkbox实现明文显示密码
- 【学习笔记】imageview,checkbox
- CheckBox,ImageView,ListView
- RadioButton、CheckBox和ImageView
- android使用CheckBox显示隐藏输入的密码
- android 根据checkBox动态控制密码的显示和隐藏
- login界面 checkbox选择显示或者隐藏密码
- 通过checkBox复选框来隐藏和显示密码
- 安卓开发点击CheckBox显示明文密码
- AdapterView
- AdapterView
- AdapterVIew
- AdapterView
- 1.自定义checkbox 2.根据checkbox让密码显示与隐藏
- HTML常用标签
- Spiral Matrix II
- android 串口扩展(wk2xxx)移植
- 【JavaScript基础知识】——运算符
- css3选择器
- Checkbox ImageView AdapterView 密码显示
- xml格式保存信息到文件
- 【LeetCode】(137)Single Number II(Medium)
- 像素单位px、dp、sp的区别与理解
- Tomcat 7 域名访问配置一
- 【Material Design】Toolbar使用
- Java IO与NIO
- 2015/8/24/自定义Adapter
- LeetCode(30) Substring with Concatenation of All Words