笔记
来源:互联网 发布:php执行exec权限不足 编辑:程序博客网 时间:2024/06/07 00:28
9,Student st=new Student();
st.setname("李");
List<Student> cl1=new ArrayList<Student>();
cl1.add(st);
List<Student> cl2=new ArrayList<Student>();
cl2.add(st);
cl1.get(0).setname("王");
cl1.get(0).setname("赵");
System.out.println(cl1.get(0).getname());
System.out.println(cl2.get(0).getname());
都输出 赵
11 v.getBackground().setAlpha(100);是错误的应该用 viewHolder.tv_action_icon_endtime.getBackground().mutate().setAlpha(204);
//0~255透明度值 ,0为完全透明,255为不透明
13,@null 背景为空
15,重写方法中用super是java中的多态有重写方法被子类重写后 父类的原方法就会被影藏当你又需要调用父类所定义的原方法
这个时候就可以用super来调用
16,//获取系统时间格式化为Data形式
Date date=new Date(long);
DateFormat fmt = new SimpleDateFormat("yyyyMMdd");
parse解析String format格式化Date类型
Date currentDate = new Date(System.currentTimeMillis());
currentDate.setMinutes(currentDate.getMinutes() - 1);
currentDate.getTime() //将时间毫秒化
long long1=Date.getTime(); //long和Date的相互转化
new Date(long);
17,StringUtils.isEmpty() isBlank()区别isEmpty()的就是 " "这样也是空
20.适配器里面v.getTag()获取对象
21.setClickable(true);是否可被点击
23.int index = new Random().nextInt(max(int)); 随机数
24.异步线程和UI线程在执行过程中,异步线程因为是异步的,所以要在异步线程里面做更新UI的操作,
因为在里面才知道异步线程执行完毕所以时刻注意使用异步线程AsyncTask和Handle的时候注意线程是否执行完毕的问题
25.注意UI线程和子线程的使用位置不能乱用
26,释放图片资源@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
if (bitmap != null) {
bitmap.recycle();
bitmap = null;
}
27,在fragment中使用
View view = inflater.inflate(R.layout.fragment_community_listview,container,false);
28,TextView android:singleLine="true"
android:ellipsize="end"
android:maxEms="8"
1.listview 的item不可点击焦点被抢
将ListView中的Item布局中的子控件focusable属性设置为false
在getView方法中设置button.setFocusable(false)
设置item的根布局的属性android:descendantFocusability="blocksDescendants"
2.listview复用错乱 可以在适配器里面创建List<Integer> contains 进行比对判断,需要remove的时候是remove(Intger)
8,TextView增加图片 android:drawablePadding="10dp"
android:drawableLeft="@drawable/back_down"
Drawable man_icon = ContextCompat.getDrawable(this,R.drawable.mine_icon_man);
man_icon.setBounds(0, 0, man_icon.getMinimumWidth(), man_icon.getMinimumHeight());
setCompoundDrawablePadding(10);
tv_useraccount.setCompoundDrawables(null, null, woman_icon, null);
行间距android:lineSpacingExtra
10,在java代码中设置空间大小间距
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(30, 30);
params.setMargins(26, 0, 0, 10);
textView.setLayoutParams(params);
RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
lp.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
params_goto.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
btn1.setLayoutParams(lp);
13,android数值dp和px之间的相互转化
private int dp2px(int dp)
{
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
getResources().getDisplayMetrics());
}
14. //listview监听中获取局部控件
public OnItemClickListener listenerlist = new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
LinearLayout layout_wai_ll=(LinearLayout) view.findViewById(R.id.layout_wai);
CheckBox layout_nei1=(CheckBox) view.findViewById(R.id.check_item_img_cb);
}
15. scrollview 注意焦点问题不然容易位置变动
android:descendantFocusability="beforeDescendants"
android:focusable="true"
android:focusableInTouchMode="true"
当listview抢焦点时在listview的父层线性布局或者相对布局上加
android:focusableInTouchMode=”true”
android:focusable=”true”
16,fragment上面的重写方法基于activity,所以viewpager的fragment的重写方法会同时调用
17.控件位置 int xPos = view.getWidth() / 2 - pop.getWidth() / 2;
int[] location = new int[2];
view.getLocationOnScreen(location);
int yInt = (int) (pop.getHeight());
pop.showAtLocation(view, Gravity.NO_GRAVITY, xPos, location[1] - yInt);
19, Intent intent = new Intent(AddOrModifyBankBranchActivity.this, backClass);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
20,listview显示到底部
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
20, adb install apk地址+**.apk 查看模拟名 adb devices -l adb端口号5037