Question

Can we have an edit text box inside our menu which gets displayed in the action bar and if we can then how can we get click events on this edit text ?

Was it helpful?

Solution

You can add a search bar to the action bar but not as a menu item... what do you even meen with "as a menu item"?

OTHER TIPS

I found the solution. It is done like this (only for android 3.0 honeycomb) Placing an edit text in action bar for placing the items use this TAG in your item in the menu xml

android:actionLayout="@layout/search_bar"

define edit text & button in the search_bar layout.

Now for getting listeners on them do it like this - in onCreateOptionsMenu()

et = (EditText) menu.findItem(R.id.search_bar).getActionView().findViewById(R.id.searchbar);        
findBtn = (ImageButton)menu.findItem(R.id.search_bar).getActionView().findViewById(R.id.find);

and then place listeners for these items. It will work fine

I havent tried it but are you able to use actionlayout from code? in that way you could use get the Text box this way:

LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE); 
LinearLayout wrapper = (LinearLayout) inflater.inflate(R.layout.random_layout, null); 
EditText editText = (EditText )wrapper.findViewById(R.id.edit); 

// 
//code to set the listener 
// 

// 
//set the android:actionLayout to wrapper etc. 
//

Im at work so I can't make some research so this is just speculations...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top