1

Unable to resolve 'search' in R.layout.search.

Here is my code of the main activity:-

package com.example.pc.samplemap;

import android.support.v7.app.ActionBar;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.example.pc.samplemap.R;
import android.view.LayoutInflater;
import android.view.View;

public class MainActivity extends AppCompatActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setDisplayShowTitleEnabled(false);
    }

    LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflator.inflate(R.layout.search, null);

    if (actionBar != null) {
        actionBar.setCustomView(v);
    }
}

}

What is the problem here? I cleaned and rebuild the code. And yet, it says cannot resolve symbol 'search'.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
CoderPJ
  • 991
  • 6
  • 18
  • 41

1 Answers1

0

You need to have a layout named search.xml in your res/layout folder. This would be the file where you'll show the search results.

Make sure that's it's included. See this StackOverflow post for more insights.

Community
  • 1
  • 1
Raman Sahasi
  • 30,180
  • 9
  • 58
  • 71
  • I don't have a search.xml file. Can you please give me the code for search.xml? I want a search field to appear on the action bar – CoderPJ Oct 24 '16 at 05:27
  • @AshikPanchangam Please follow this link: http://stackoverflow.com/a/35347987/2815219 – Raman Sahasi Oct 24 '16 at 05:33