1

我正在开发一个将在网站中搜索特定单词的android..为此我开发了一些代码...但它不完整...有谁能提供帮助...这将有助于我……非常感谢你的阅读

 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);
     }
}
4

1 回答 1

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;
                   }
           });
于 2013-04-05T06:41:05.587 回答