-
字符串处理
1.字符串分割:split(); 结合正则效果极佳
2.正则表达式
3. 字符串截取 indexof()
4. 字符串判断 contains()
5. 字符串替换 replace(), replaceAll,结合正则
6. 字符串换颜色 SpannableStringBuilder -
常用的布局
1.LRecyclerView ①下拉刷新,上滑加载②设置空页面
public abstract class ListBaseAdapter<T> extends RecyclerView.Adapter<SuperViewHolder> { protected Context mContext; private LayoutInflater mInflater; protected List<T> mDataList = new ArrayList<>(); public ListBaseAdapter(Context context) { mContext = context; mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override public SuperViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View itemView = mInflater.inflate(getLayoutId(), parent, false); return new SuperViewHolder(itemView); } @Override public void onBindViewHolder(SuperViewHolder holder, int position) { onBindItemHolder(holder, position); } //局部刷新关键:带payload的这个onBindViewHolder方法必须实现 @Override public void onBindViewHolder(SuperViewHolder holder, int position, List<Object> payloads) { if (payloads.isEmpty()) { onBindViewHolder(holder, position); } else { onBindItemHolder(holder, position, payloads); } } public abstract int getLayoutId(); public abstract void onBindItemHolder(SuperViewHolder holder, int position); public void onBindItemHolder(SuperViewHolder holder, int position, List<Object> payloads){ } @Override public int getItemCount() { return mDataList.size(); } public List<T> getDataList() { return mDataList; } public void setDataList(Collection<T> list) { this.mDataList.clear(); this.mDataList.addAll(list); notifyDataSetChanged(); } public void addAll(Collection<T> list) { int lastIndex = this.mDataList.size(); if (this.mDataList.addAll(list)) { notifyItemRangeInserted(lastIndex, list.size()); } } public void remove(int position) { this.mDataList.remove(position); notifyItemRemoved(position); if(position != (getDataList().size())){ // 如果移除的是最后一个,忽略 notifyItemRangeChanged(position,this.mDataList.size()-position); } } public void clear() { mDataList.clear(); notifyDataSetChanged(); }}
public class ReciteRecordsAdapter extends ListBaseAdapter<Record.DataBean>
2. CardView :关于z轴,就是浮动,cardview有z轴增量,使用时注意覆盖问题 3. RelativeLayout:该项目中的基本布局,好用! 4. ScrollView:自动滑动,测量view高度问题(oncrate()时,测量为0,因为视图还未绘制,用下面方式测量)
sc_view.post(new Runnable() { @Override public void run() { x = sc_view.getHeight(); Log.e("zjq-run", x + ""); } }); if (tv_recite_content2.getHeight() + 200 > x) { //Log.e("zjq-x-2", x + "-" + (mainindex + 1 - x) + ""); sc_view.scrollBy(0, 30); x += 40; }
-
控件
1.CheckBox:多选逻辑问题(全选,全不选等)
· (当子选项全部选中,全选按钮自动选中) int num = 0; for (int i = 0; i < mAdapter.getDataList().size(); i++) { //只要有一个不被选中 if (!mAdapter.getDataList().get( i ).getCheck()) { checkAll.setChecked( false ); } else { num++; } } if (num == mAdapter.getDataList().size()) { checkAll.setChecked( true ); } · (当全选按钮选中,子选项全部选中) if (checkAll.isChecked()) { checkAll_or_No( true ); } else { checkAll_or_No( false ); } private void checkAll_or_No(boolean isCheck) { if (mDataList != null && mDataList.size() > 0) { //有数据 for (int i = 0; i < mDataList.size(); i++) { Record.DataBean record = mDataList.get( i ); record.setCheck( isCheck ); //刷新适配器 notifyItemChanged( i ); } } }
2.TextView:①监听文本内容:addTextChangedListener ②TextView.setText(char[] text, int start, int len);
-
缓存
1.SharedPreferences
2.AChaceSharedPreferences.Editor editor = getSharedPreferences("Recite_data_zjq", MODE_PRIVATE).edit(); editor.putString("name", name); editor.apply(); ------------------------------ SharedPreferences preferences = getSharedPreferences("Recite_data_zjq", MODE_PRIVATE); =========== grade = preferences.getString("grade", ""); ------------------------------ aCache.put("grade",grade);
ACache aCache=ACache.get(this); grade = aCache.getAsString("grade");
-
Handler
handler = new MyHandler(); private class MyHandler extends Handler { public void handleMessage(Message msg) {} }
-
Josn解析
1.JSONObject
2.Gson:ArrayList list_item = new Gson().fromJson(data.toString(), new TypeToken<List<Grade.DataBean>>() { }.getType());
-
网络框架
1.OkHttpUtils
-
Dialog提示框
public class AlertDialog extends Dialog { AlertController mAlert; public AlertDialog(@NonNull Context context, @StyleRes int themeResId) { super(context, themeResId); mAlert = new AlertController(this, getWindow()); } public void setText(int viewId, CharSequence text) { mAlert.setText(viewId, text); } public void setOnClickListener(int viewId, View.OnClickListener listener) { mAlert.setOnClickListener(viewId, listener); } /** * 减少findviewById的次数 */ public <T extends View> T getView(int viewId) { return mAlert.getView(viewId); } public static class Builder { private final AlertController.AlertParams P; public Builder(@NonNull Context context) { this(context, R.style.dialog); } public Builder(@NonNull Context context, @StyleRes int themeResId) { P = new AlertController.AlertParams(context, themeResId); } public AlertDialog create() { final AlertDialog dialog = new AlertDialog(P.mContext, P.themeResId); P.apply(dialog.mAlert); dialog.setCancelable(P.mCancelable); if (P.mCancelable) { dialog.setCanceledOnTouchOutside(true); } dialog.getWindow().setBackgroundDrawable(new ColorDrawable()); dialog.setOnCancelListener(P.mOnCancelListener); dialog.setOnDismissListener(P.mOnDismissListener); if (P.mOnKeyListener != null) { dialog.setOnKeyListener(P.mOnKeyListener); } return dialog; } /** * 设置View */ public AlertDialog.Builder setContentView(int layoutResId) { P.mView = null; P.mViewLayoutResId = layoutResId; return this; } public AlertDialog.Builder setContentView(View view) { P.mView = view; P.mViewLayoutResId = 0; return this; } /** * 存放自定义View中的文本 */ public AlertDialog.Builder setText(int layoutId, CharSequence text) { P.mTextArray.put(layoutId, text); return this; } /** * 存放自定义View中按钮点击事件 */ public AlertDialog.Builder setOnClickListener(int layoutId, View.OnClickListener listener) { P.mClickArray.put(layoutId, listener); return this; } //配置一些万能参数 public AlertDialog.Builder fullWidth() { P.mWidth = ViewGroup.LayoutParams.MATCH_PARENT; return this; } //设置动画 public AlertDialog.Builder fromButtom(boolean isAnimation) { if (isAnimation) { P.mAnimation = R.style.dialog_from_bottom_anim; } P.mGravity = Gravity.BOTTOM; return this; } public AlertDialog.Builder setWidthAndHeight(int width, int heigth) { P.mWidth = width; P.mHeigth = heigth; return this; } //设置默认动画 public AlertDialog.Builder AddDefaultAnimation() { P.mAnimation = R.style.dialog_scale_anim; return this; } //设置动画 public AlertDialog.Builder setAnimation(int styleAnimation) { P.mAnimation = styleAnimation; return this; } public AlertDialog show() { final AlertDialog dialog = create(); dialog.show(); return dialog; } }}
final AlertDialog dialog = new AlertDialog.Builder(ReciteContentActivity.this) .setContentView(R.layout.common_prompt_alert) .setText(R.id.buyactivity_sure, "确定") .setText(R.id.buyactivity_sure_aler_tv1, "您当前背诵间隔时间过长,中断本次背诵,可重新开启") .show(); handler.removeMessages(5); //其它地方失去焦点 dialog.setCancelable(false); dialog.findViewById(R.id.li_alert_cancel).setVisibility(View.GONE); dialog.setOnClickListener(R.id.buyactivity_sure, new View.OnClickListener() { @Override public void onClick(View v) { over(); /* //去背诵结果页面 Intent intent = new Intent(ReciteContentActivity.this, ReciteResultsActivity.class); startActivity(intent);*/ dialog.dismiss(); } });
03-09
04-17
10-06
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交