在android中搜索一个网站

时间:2013-04-05 06:07:26

标签: java android web

我正在开发一个能够在网站中搜索特定单词的机器人...因为我开发了一些代码......但它并不完整......是否有人能够提供帮助..这将是帮助我...非常感谢你阅读

 public class MainActivity extends Activity {

    EditText et = new EditText(this);

     public void onClick(View v){
         Editable searchText = et.getText();
         Intent intent = new Intent(this, com.example.app.MainActivity.class);
         intent.putExtra("searchQuery", searchText);
         startActivity(intent);
     }
}

1 个答案:

答案 0 :(得分:1)

试试吧......

<EditText
    android:id="@+id/edt_search"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent"
    android:ellipsize="end"
    android:hint="Enter Your Text"
    android:imeOptions="actionGo"
    android:singleLine="true"
    android:textSize="14sp" />

EditText edt_search;

edt_search = (EditText) findViewById(R.id.edt_search_book);
edt_search.setImeOptions(EditorInfo.IME_ACTION_GO);

edt_search.setOnEditorActionListener(new OnEditorActionListener() {
                   public boolean onEditorAction(TextView v, int actionId,
                                   KeyEvent event) {
                           // Log.i("KeyBoard" ,"Inside the Edit Text");
                           if (actionId == EditorInfo.IME_ACTION_GO) {

                               Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
                               intent.putExtra(SearchManager.QUERY, edt_search.getText().toString()); // query contains                                                                                               
                               startActivity(intent); // search string

                           }
                           return false;
                   }
           });