1

I need to search in a web page..I developed and android application..in which when the user presses the button the web page wiill be opened but i need the user to enter a keyword and when user press the button that keyword has to serch inside the web page..i am providng my coe here can u pls suggest what i have to do next

Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn1=(Button) findViewById(R.id.button1);
        ev = (EditText) findViewById(R.id.editText1);

        btn1.setOnClickListener(new View.OnClickListener() 
        {


            @Override
            public void onClick(View v) 

            {
                 Intent intent = new Intent(Intent.ACTION_VIEW,
                 Uri.parse("http://www.androidaspect.com"));

                 startActivity(intent);    
            }
       });
    }
thepoosh
  • 12,497
  • 15
  • 73
  • 132
user2223317
  • 211
  • 1
  • 3
  • 13
  • Try this http://stackoverflow.com/questions/2376471/how-do-i-get-the-web-page-contents-from-a-webview – Pragnani Apr 09 '13 at 10:59

1 Answers1

1

First you need to load url into your WebView. Then use javascript in your Webview to search. You can use this javascript for searching

$(document).ready(function() {
    function trim(value) {
        var temp = value;
        var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
        if (obj.test(temp)) {
            temp = temp.replace(obj, '$2');
        }
        var obj = / +/g;
        temp = temp.replace(obj, " ");
        if (temp == " ") {
            temp = "";
        }
        return temp;
    }
    var body = $('body');

    SearchQueue("of Micro");

    function SearchQueue(text) {
        if (text !== null) {
            text = text.replace(/^\s*$[\n\r]{1,}/gm, ''); // Removing empty line breaks
            text = text.replace(/”/g, "\"");
            text = text.replace(/“/g, "\"");
            text = text.replace(/”/g, "\"");
            text = text.replace(/’/g, "\'");
            text = text.replace(/‘/g, "\'");
            text = text.replace(/–/g, "\-");
            text = text.replace(/—/g, "\-");
            text = text.replace(/–/g, "\-");
            var txt1 = text;
            text = trim(txt1);
            var SearchItems = text.split(/\r\n|\r|\n/);
            var replaced = body.text();
            for (var i = 0; i < SearchItems.length; i++) {
                var tempRep = '<span class="highlight" style="background-color: yellow">';
                tempRep = tempRep + SearchItems[i];
                tempRep = tempRep + '</span>';
                replaced = replaced.replace(SearchItems[i], tempRep);
            }
            $("body").html(replaced);
        }
    }
    shortcut.add("Ctrl+Z", function() {
        $('.highlight').toggleClass();
    });

    shortcut.add("Ctrl+V", function() {
        var txt = window.clipboardData.getData("Text");
        var ClipText = txt.replace(/[a-zA-Z0-9\?\&\=\%\#]+s\=(\w+)(\&.*)?/, "$1");
        SearchQueue(ClipText.replace(/\%20|\+/g, "\|"));
    });
});
Arun C
  • 9,035
  • 2
  • 28
  • 42