I have this markup:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <AutoCompleteTextView android:id="@+id/autoCompleteTextView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="" android:hint="Найти собеседника..."> <requestFocus /> </AutoCompleteTextView> <ListView android:focusable="false" android:focusableInTouchMode="false" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/listView" android:layout_gravity="center_horizontal" tools:listitem="@android:layout/simple_list_item_2" /> </LinearLayout> 

Found an example in the network, but I do not understand where to insert it? Wherever I insert I always write errors in the markup.

 <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity"> <item android:id="@+id/action_settings" android:orderInCategory="100" android:title="@string/action_settings" app:showAsAction="never"/> </menu> 
  • you have an error in the markup - in the second example you have the <menu> tag not closed - there is no closing of the tag, </ menu> - Ksenia

1 answer 1

Well, in general, the menu layout, apparently, from the example of the actionbar's menu. It does not need to be inserted into the activation markup. it is added programmatically:

 @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); //здесь указываешь на файл разметки меню return true; } //обработка нажатия @Override public boolean onOptionsItemSelected(MenuItem item) { switch(item.getItemId()) { case R.id.action_settings: //add the function to perform here return(true); } return(super.onOptionsItemSelected(item)); }