一、
是可以在adapter中给item设置监听事件,让其跳转页面
viewHodler.cv_hread.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(context, HisActivity.class); intent.putExtra("user_id", blogFollow.getUserId()); context.startActivity(intent); } });
注意:startActivity前用context调用
二、
ScroolView嵌套listview时,listview只显示一行问题解决
/** * 用于解决ScrollView嵌套listview时,出现listview只能显示一行的问题 * * @param listView */ public void setListViewHeightBasedOnChildren(ListView listView) { // 获取ListView对应的Adapter ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) { return; } int totalHeight = 0; for (int i = 0, len = listAdapter.getCount(); i < len; i++) { // listAdapter.getCount()返回数据项的数目 View listItem = listAdapter.getView(i, null, listView); // 计算子项View 的宽高 listItem.measure(0, 0); // 统计所有子项的总高度 totalHeight += listItem.getMeasuredHeight(); } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); // listView.getDividerHeight()获取子项间分隔符占用的高度 // params.height最后得到整个ListView完整显示需要的高度 listView.setLayoutParams(params); }
三、
progressBar
setIndeterminate(true)的意思就是不明确具体进度,进度条在最大值与最小值之间来回移动,形成一个动画效果,就是仅仅告诉你,我在工作,但是无法知道工作到那个阶段,而setIndeterminate(false)则相反,可能你会有疑问,为什么true的时候是不确定,false的时候反而是确定的呢?因为indeterminate本身是不确定,不明确的意思,负负得正知道吧?就是这个意思
从R文件的id取字符串, getString(R.string.progress)
showProgressDialog(this, getString(R.string.progress),true)
四、设定字体为粗体
holder.tv_no.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
五、头布局toolba的RelativeLayout设置可点击
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@id/rl_hreader" android:clickable="true"
六、给popupwindow设置背景
ColorDrawable dw = new ColorDrawable(0xb0000000); this.setBackgroundDrawable(dw);
七、拿到填充器
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
八、JAVA中int、String的类型转换
int -> String int i=12345; String -> int s="12345"; |
int -> String int i=12345; String -> int s="12345"; |
第一种方法:s=i+"";
第二种方法:s=String.valueOf(i); //直接使用String类的静态方法,只产生一个对象
第一种方法:i=Integer.parseInt(s);//直接使用静态方法,不会产生多余的对象,但会抛出异常
第二种方法:i=Integer.valueOf(s).intValue();//Integer.valueOf(s) 相当于 new Integer(Integer.parseInt(s)),也会抛异常,但会多产生一个对象
int -> String int i=12345; String -> int s="12345"; |