1

在我的活动中,这一行(Home.this,android.R.layout.activity_home, searchResults));中有一个错误,上面写着“activity_home 无法解决”,但是如果我按照教程之一中提到的那样给出 single_list_item_1,错误就会消失,因为这个错误我已经在 res 中检查了大写字母,然后清理了项目,但仍然无法摆脱这个。

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) {

                   }
                  });
4

2 回答 2

2

android.R.layout.activity_home

开头的东西android是预定义的android资源。

如果您想使用自己的布局,例如activity_home.xml

你必须以这种方式使用它

R.layout.activity_home

这意味着您的应用程序资源。

于 2013-02-15T10:02:22.800 回答
1

android.R.layout.activity_home你必须了解和之间的区别R.layout.activity_home。第一个将尝试从 android 的预定义布局集合中加载布局,而另一个位于您的项目布局文件夹中

于 2013-02-15T10:01:25.130 回答