Android 问题整理 五

// popupwindow使用之异常-Unable to add window — token null is not valid; is your activity running?

https://blog.csdn.net/u011005173/article/details/53085148

// List ArrayList 反转

private List<LogisticsDetailModel.ResponseBean.TracesBean> tracesBeanList = new ArrayList<>();


 Object objtracesList = detailModel.getResponse().get(0).getTraces();
        String strtracesList = new Gson().toJson(objtracesList);
        TypeToken typetracesList = new TypeToken<List<LogisticsDetailModel.ResponseBean.TracesBean>>() {
        };
        tracesBeanList = new Gson().fromJson(strtracesList, typetracesList.getType());
//        Log.e("WaitPayOrderDetailAty","=="+orderListBeanList.get(0).getAdd_time());
        Collections.reverse(tracesBeanList);// 反转的类
        logisticsDetailAdapter.setTracesBeanList(tracesBeanList);
        ald_RV.setAdapter(logisticsDetailAdapter);

// activityParent + fragmentParentA + fragmentChildB(activity 销毁后,进入fragmentParentA , getActivity() 为 null)

fragment 嵌套

...
public class HomeFragment2 extends Fragment {
...
    public FragmentActivity myContext;
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fg_home2, null);
        myContext = getActivity(); // 在使用到 getActivity() 的地方替换)
        handler.post(runnable);
        return view;
    }

    private void initFragment(View view) {
//        FragmentPagerItems pages = new FragmentPagerItems(getActivity());
        FragmentPagerItems pages = new FragmentPagerItems(myContext);
        for (int i = 0; i < totaltitle.size(); i++) {
            if (totaltitle.get(i).getCat_name().equals("精选")) {
                pages.add(FragmentPagerItem.of(totaltitle.get(i).getCat_name(), FgHome2FgA.class));
            } else {
                pages.add(FragmentPagerItem.of(totaltitle.get(i).getCat_name(), FgHome2FgB.class));
            }
        }
        Log.e("HomeFragment2","=getActivity="+myContext);
        FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
                myContext.getSupportFragmentManager(), pages);
        if (adapter != null) {
            BaseApp.setContext(myContext);
            viewPager = view.findViewById(R.id.fg_home2_VP);
            viewPager.setAdapter(adapter);

            SmartTabLayout viewPagerTab = view.findViewById(R.id.fg_home2_STL);
            viewPagerTab.setViewPager(viewPager);
        }
    }
}

// 数组,对象数组,List 转 json,Json,对象数组转 Json


// Textview 文本显示的货币符号 — 人民币符号只有一横,应该为两横

一横    ¥
两横    ¥

// ButterKnife 在 Recyclerview 的 Adapter 中使用 参考这里

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iavminv_goods_img_IV)
        ImageView iavminv_goods_img_IV;
        @BindView(R.id.iavminv_goods_name_IV)
        TextView iavminv_goods_name_IV;
        @BindView(R.id.iavminv_goods_price_IV)
        TextView iavminv_goods_price_IV;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

// 动态修改 ImageView 的宽高

 holder.iavminv_goods_img_IV.setLayoutParams(new LinearLayout.LayoutParams(aaa, aaa));

// Android Studio 3.2.1 编译很慢 参考这里

修改配置,将 gradle 设置为 offline work 注:前几次可能慢,2次以后就会逐渐变快

org.gradle.jvmargs=-Xmx3062m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.daemon=true

-Xms1024m
-Xmx2048m
-XX:ReservedCodeCacheSize=240m
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=50
-Dsun.io.useCanonCaches=false
-Djava.net.preferIPv4Stack=true
-Djna.nosys=true
-Djna.boot.library.path=

-da

// pom jar 文件找不到 参考这里国内可用maven repository 配置

如果还是不行,再执行一下这个


// RecyclerView.Adapter 中PopupWindow 弹出后,禁止返回键退出当前的 activity,PopupWindow dismiss() 后,点击返回键退出当前的 activity。

// RecyclerView.Adapter 中使用
 private OnIsShowPopupWindow mOnIsShowPopupWindow;

// PopupWindow 显示的时候使用
if (mOnIsShowPopupWindow != null) {
	mOnIsShowPopupWindow.onIsShowPopupWindow(true);
}	
		
// PopupWindow dismiss()的时候使用
if (mOnIsShowPopupWindow != null) {
	mOnIsShowPopupWindow.onIsShowPopupWindow(false);
}
				
// 定义监听的接口
public interface OnIsShowPopupWindow{
	void onIsShowPopupWindow(boolean isShow);
}

public void setOnIsShowPopupWindow(OnIsShowPopupWindow mOnIsShowPopupWindow) {
	this.mOnIsShowPopupWindow = mOnIsShowPopupWindow;
}
// Activity 中使用
private ShareFightAda shareFightAda;
private boolean misShow;

shareFightAda = new ShareFightAda(mActivity, tfListItem);
shareFightAda.setOnIsShowPopupWindow(new ShareFightAda.OnIsShowPopupWindow() {
	@Override
	public void onIsShowPopupWindow(boolean isShow) {
		misShow = isShow;
	}
});
		
		
@Override
public void onBackPressed() {
	if (!misShow) {
		super.onBackPressed();
	}
}

// ViewPager 懒加载的问题

// 参数代表加载当前界面左右两边的内容页数,这里加载数量为总共为7
viewPager.setOffscreenPageLimit(3);

// 圆形图片

        Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), R.mipmap.img);

        RoundedBitmapDrawable circularBitmapDrawable =
                RoundedBitmapDrawableFactory.create(this.getResources(), bitmap);
        circularBitmapDrawable.setCircular(true);
        imageView.setImageDrawable(circularBitmapDrawable);


// Android studio build 日志报错分析,build的报错转换为文本模式


// 使用搜索引擎的时候,排除CSDN 的内容,搜索结果不包含 CSDN 的内容

-site:csdn.net

// http,okhttp,httputil,post请求参数组装,网络请求

CheckGoods.ParamsBean bean = new CheckGoods.ParamsBean();
bean.setCancel(cancel);
bean.setChecked(checked);

CheckGoods checkGoods = new CheckGoods();
checkGoods.setAction("checkGoods");
checkGoods.setUnionid(unionid);
checkGoods.setVersion(XMW_VERSION);
checkGoods.setParams(bean);
String params = new Gson().toJson(checkGoods);
fg_shopp_cart_PB.setVisibility(View.VISIBLE);
Log.e("checkGoods", "==" + paramsa);
HttpUtil.postRequestString(XMW_CHECK_OUT_ORDER, params, new StringCallback() {

// Json 格式,手动json格式

    @Override
    public String toString() {
        return "{\"type\":" + news_type + ", " +
                "\"data\":{" +
                "\"order_id\":" + "\"" + news_order_id + "\"" +
                ",\"course_id\":" + "\"" + news_course_id + "\"" +
                ",\"news_id\":" + "\"" + news_id + "\"" +
                ",\"news_time\":" + "\"" + news_time + "\"" +
                ",\"news_type\":" + "\"" + news_type + "\"" +
                ",\"news_to_id\":" + "\"" + news_to_id + "\"" +
                ",\"course_img\":" + "\"" + course_img + "\"" +
                ",\"img\":" + "\"" + img + "\"" +
                ",\"title\":" + "\"" + title + "\"" +
                ",\"detail\":" + "\"" + detail + "\"" +
                ",\"extra\":" + "\"" + extra + "\"" +
                "}}";
    }
{
	"type": 1,
	"data": {
		"order_id": "485",
		"course_id": "1428",
		"news_id": "94",
		"news_time": "2019-08-05 11:27",
		"news_type": "1",
		"news_to_id": "null",
		"course_img": "https://img.xiongmaotaoxue.com/image/20190805/20190805112259_60782.jpg",
		"img": "null",
		"title": "null",
		"detail": "null",
		"extra": "null"
	}
}

// 集成微信 sdk 版本号查看地址

https://bintray.com/wechat-sdk-team/maven

2020-06-16-22-29:

implementation 'com.tencent.mm.opensdk:wechat-sdk-android-with-mta:5.4.0'

// 微信支付失败

参考微信开发官网1    参考微信开发官网2

正确的签名算法

        String signA = "appid=" + appId + "&noncestr=" + nonceStr
                + "&package=Sign=WXPay&partnerid=" + partnerId
                + "&prepayid=" + prepayId
                + "&timestamp=" + timeStamp;
        String signB = signA + "&key=" + "4XcM4YlnT5xRzwgNrf0BGzhWn3aOItn0";

         String signx = getMd5Value(signB);

“&key” 该 key 为:

md5加密

    public static String getMd5Value(String sSecret) {
        try {
            MessageDigest bmd5 = MessageDigest.getInstance("MD5");
            bmd5.update(sSecret.getBytes());
            int i;
            StringBuffer buf = new StringBuffer();
            byte[] b = bmd5.digest();// 加密
            for (int offset = 0; offset < b.length; offset++) {
                i = b[offset];
                if (i < 0)
                    i += 256;
                if (i < 16)
                    buf.append("0");
                buf.append(Integer.toHexString(i));
            }
            return buf.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }

 

发表评论

zh_CNChinese
zh_CNChinese