问题:在鸿蒙HarmonyOS开发中,有一个2x2的卡片,想点击不同区域有不同的事件,为什么会只响应最后一次?
问题追加: 以下是部分代码1: private IntentAgent startAbilityIntentAgent(String keyword) { Intent intent = new Intent(); Operation operation = new Intent.OperationBuilder() .withBundleName("cn.felix.widget_sample") .withAbilityName("cn.felix.widget_sample.TestAbility") .build(); intent.setOperation(operation); intent.setParam("test", keyword); List<Intent> intentList = new ArrayList<>(); intentList.add(intent); List<IntentAgentConstant. Flags> flags = new ArrayList<>(); flags.add(IntentAgentConstant.Flags.UPDATE_PRESENT_FLAG); IntentAgentlnfo paramslnfo = new IntentAgentInfo( requestcode: 200, IntentAgentConstant.OperationType.STAF return IntentAgentHelper.getIntentAgent( context: this, paramslnfo); } 以下是部分代码2: ProviderFormlnfo providerFormlnfo = new ProviderFonnInfo(ResourceTable.Layout_fonn_image_with_info_service_widget_2_2, context: this); Componentprovider provider = new ComponentProvider(); provider.setText(ResourceTable.Id_tv_card_detail, text: "Title!"); //点击控制事件 provider.setIntentAgent(ResourceTable.Id_action1, startAbilityIntentAgent( keyword: "action_1")); provider.setIntentAgent(ResourceTable.Id_action2, startAbilityIntentAgent( keyword: "action_2")); provider.setlntentAgent(ResourceTable.Id_action3, startAbilityIntentAgent( keyword: "action_3")); provider.setIntentAgent(ResourceTable.Id_action4, startAbilityIntentAgent( keyword: "action_4")); //填充数据到卡片 providerFormlnfo.mergeActions(provider); return providerFormlnfo;
回答: 每个区域requestcode要不一样。
说明: 经实测,以上代码接受了以上建议,可以解决该问题。 |