2012-11-08 4 views
0

invoke 메서드의 인수를 올바르게 사용할 수있는 방법을 알려주십시오.BlackBerry의 Object invoke (Object thiz, Object [] args) 메서드 사용

browserField.extendScriptEngine("interesting.test", new ScriptableFunction() { 

    public Object invoke(Object thiz, Object[] args) throws Exception { 

     Dialog.alert("Done"); 

     return super.invoke(thiz, args); 
    } 
}); 

다음과 같이 HTML 파일에서 위의 메소드를 호출합니다. 나는 다음 코드를 사용하십시오

<button type="button" onclick="interesting.test()">Display Alert</button> 

System.out.println("# thiz : " + thiz.toString()); 

결과는

[0.0] # thiz : net.[email protected]a2f32d2a 

내가이 코드를 사용할 때

System.out.println("# args : " + args.length); 

결과는

입니다
[0.0] # args : 0 

콘솔에 인쇄됩니다.

나는 System.out 메서드를 invoke 메서드 내에서 사용했습니다. 또한 API 문서를 참조했지만 여전히 두 인수에 값을 전달하고 검색하는 방법을 이해할 수 없었습니다. 당신이 시도 할 수

답변

0

, 그것은

  try{ 

       browserField.extendScriptEngine("interesting.test", new ScriptableFunction() { 

       public Object invoke(Object thiz, static Object[] args) throws Exception { 

        Dialog.alert(String.valueOf(args[0]).toString()); 

       } 
       }); 

      } catch(Exception e){ 
       // 
      } 

나를 위해 일한 그 인수가 하나 개 이상의 매개 변수에서 데 의미 수있는 개체 단순히 배열 때문에 다음 HTML에서이

<button type="button" onclick="interesting.test('cool')">Display Alert</button> 

을 융통성있는 목적을 위해 같은 시간, 자바 스크립트에서 사용되는 인수와 비슷한 그것의 종류. 그래서 그것을 밖으로 시도하십시오 ...

관련 문제