hey!!
package fyp.android.first;
/*
* Copyright (C) 2008 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
//import com.google.android.samples.R;
public class firstapplication extends Activity
{
// UI elements
Button mStartSearch;
Spinner mMenuMode;
EditText mQueryPrefill;
EditText mQueryAppData;
// Menu mode spinner choices
// This list must match the list found in
samples/ApiDemos/res/values/arrays.xml
final static int MENUMODE_AUTOMATIC = 0;
final static int MENUMODE_MENU_ITEM = 1;
final static int MENUMODE_DISABLED = 2;
/**
* Called with the activity is first created.
*
* We aren't doing anything special in this implementation, other than
* the usual activity setup code.
*/
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// Inflate our UI from its XML layout description.
setContentView(R.layout.search_invoke);
// Get display items for later interaction
mStartSearch = (Button) findViewById(R.id.btn_start_search);
mMenuMode = (Spinner) findViewById(R.id.spinner_menu_mode);
mQueryPrefill = (EditText) findViewById(R.id.txt_query_prefill);
mQueryAppData = (EditText) findViewById(R.id.txt_query_appdata);
// Populate items
ArrayAdapter<CharSequence> adapter =
ArrayAdapter.createFromResource(
this, R.array.search_menuModes,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mMenuMode.setAdapter(adapter);
// Attach actions to buttons
mStartSearch.setOnClickListener(
new OnClickListener() {
public void onClick(View v) {
onSearchRequested();
}
});
}
/**
* Called when your activity's options menu needs to be updated.
*/
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
Menu.Item item;
// first, get rid of our menus (if any)
menu.removeItem( 0 );
// next, add back item(s) based on current menu mode
switch ( mMenuMode.getSelectedItemPosition() )
{
case MENUMODE_AUTOMATIC:
item = menu.add( 0, 0, "Automatic");
break;
case MENUMODE_MENU_ITEM:
item = menu.add( 0, 0, "Search");
item.setAlphabeticShortcut( 'S' );
break;
case MENUMODE_DISABLED:
item = menu.add( 0, 0, "Disabled");
break;
}
return true;
}
/** Handle the menu item selections */
@Override
public boolean onOptionsItemSelected(Menu.Item item) {
switch (item.getId()) {
case 0:
switch (mMenuMode.getSelectedItemPosition()) {
case MENUMODE_AUTOMATIC:
showAlert( null, 0, "To invoke search, try menu+S", "OK",
true );
break;
case MENUMODE_MENU_ITEM:
onSearchRequested();
break;
case MENUMODE_DISABLED:
showAlert( null, 0, "You have disabled search", "OK", true
);
break;
}
break;
}
return super.onOptionsItemSelected(item);
}
/**
* This hook is called when the user signals the desire to start a
search.
*
* By overriding this hook we can insert local or context-specific data.
*
* @return Returns true if search launched, false if activity blocks it
*/
@Override
public boolean onSearchRequested() {
// If your application absolutely must disable search, do it here.
if (mMenuMode.getSelectedItemPosition() == MENUMODE_DISABLED) {
return false;
}
// It's possible to prefill the query string before launching the
search
// UI. For this demo, we simply copy it from the user input field.
// For most applications, you can simply pass null to startSearch()
to
// open the UI with an empty query string.
final String queryPrefill = mQueryPrefill.getText().toString();
// Next, set up a bundle to send context-specific search data (if
any)
// The bundle can contain any number of elements, using any number
of keys;
// For this Api Demo we copy a string from the user input field, and
store
// it in the bundle as a string with the key "demo_key".
// For most applications, you can simply pass null to startSearch().
Bundle appDataBundle = null;
final String queryAppDataString =
mQueryAppData.getText().toString();
if (queryAppDataString != null) {
appDataBundle = new Bundle();
appDataBundle.putString("demo_key", queryAppDataString);
}
// Now call the Activity member function that invokes the Search
Manager UI.
startSearch(queryPrefill, appDataBundle);
// Returning true indicates that we did launch the search, instead
of blocking it.
return true;
}
}
i took the code from the samples but everything with R. id is giving me
error that
and i dont know how to resolve it!!
can naybody help please??
one more thing what is this R thing!!
waiting for your answers!!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---