jack
jack

Reputation: 133

Layout name cannot be resolved in android

In my activity there is an error in this line (Home.this,android.R.layout.activity_home, searchResults)); which says "activity_home cannot be resolved" but if i give as single_list_item_1 as mentioned in one of the tutorial, error disappears, for this error i had checked in res for capital letters, then cleaned the project but still not able to get rid of this.

searchBox.addTextChangedListener(new TextWatcher() {
                 public void onTextChanged(CharSequence s, int start, int before, int count) {

                   //get the text in the EditText
                   String searchString=searchBox.getText().toString();
                   int textLength=searchString.length();
                    //clear the initial data set
                   searchResults.clear();
                   for(int i=0;i<songsList.size();i++)
                   {
                  String playerName=songsList.get(i).get("title").toString();
                  if(textLength<=playerName.length()){
                  //compare the String in EditText with Names in the ArrayList
                      if(searchString.equalsIgnoreCase(playerName.substring(0,textLength)))
                   Toast.makeText(getApplicationContext(),playerName,1).show();
                    searchResults.add(songsList.get(i));
                  }

                  list.setAdapter(new ArrayAdapter<HashMap<String, String>>
                  (Home.this,android.R.layout.single_list_item, searchResults));

                   }

                   adapter.notifyDataSetChanged();
                 }

            public void beforeTextChanged(CharSequence s, int start, int count,int after) {
              }

                   public void afterTextChanged(Editable s) {

                   }
                  });

Upvotes: 1

Views: 376

Answers (2)

Archie.bpgc
Archie.bpgc

Reputation: 24012

android.R.layout.activity_home

Something which starts with android is a predfined android resource.

if you want to use your own layout like activity_home.xml

you must use it this way

R.layout.activity_home

which means your application resource.

Upvotes: 2

Tomislav Novoselec
Tomislav Novoselec

Reputation: 4620

you have to learn the difference between android.R.layout.activity_home and R.layout.activity_home. the first one will try to load layout from android's predefined layout collection, while the other one is located in your projects layout folder

Upvotes: 1

Related Questions