开发者

How to set textview text using JavaScript Android

I want to set text in textview in my android class using JavaScript which contains a same named variable as in the class for textview to which I want to assign some text. Something like this:

In js:

function validClick() {

 fromJS.append("vikrant");

 valid.performClick();

 document.getElementById("ok").value = "Accepte";
}

fromJS is my textview in android class.

and the code in the class looks like:

    valid.setOnClickListener(new View.OnClickListener() {
        
        
        @Override
        public void onClick(View v) {
      开发者_StackOverflow中文版      // TODO Auto-generated method stub
            Context context = getApplicationContext();
            CharSequence text = fromJS.getText();
            CharSequence text = clsVariable;

            int duration = Toast.LENGTH_SHORT;
            
            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
            

        }
    });

Edit

Also, I'm writing

    wbvw.addJavascriptInterface(valid, "valid");
    wbvw.addJavascriptInterface(fromJS, "fromJS");

in my onCreate method.


Check out this link. I think it uses TextView and javascript to lad data to it.

http://divineprogrammer.blogspot.in/2009/11/javascript-rhino-on-android.html

doit(
         "var widgets = Packages.android.widget;\n" +
         "var view = new widgets.TextView(TheActivity);\n" +
         "TheActivity.setContentView(view);\n" +
         "var text = 'Hello Android!\\nThis is JavaScript in action!';\n" +
         "view.append(text);"
         );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜