未找到Android studio res/xml目录

未找到Android studio res/xml目录,android,android-studio,Android,Android Studio,我需要在我的项目中包含可搜索的配置文件,在android文档中,他们说要在res/xml目录中包含这个xml文件。但找不到xml目录。是否需要创建xml目录或将此xml文件添加到其他位置?您需要在res文件夹下创建xml目录,如res-xml将Car.xml放入xml文件夹。我添加了从xml/car.xml检索数据的示例代码 您首先需要的是一个名为searchable的XML文件 配置它配置搜索对话框的某些UI方面 或小部件,并定义建议和语音等功能 搜索行为。该文件传统上命名为searchabl

我需要在我的项目中包含可搜索的配置文件,在android文档中,他们说要在res/xml目录中包含这个xml文件。但找不到xml目录。是否需要创建xml目录或将此xml文件添加到其他位置?

您需要在res文件夹下创建xml目录,如res-xml将Car.xml放入xml文件夹。我添加了从xml/car.xml检索数据的示例代码

您首先需要的是一个名为searchable的XML文件 配置它配置搜索对话框的某些UI方面 或小部件,并定义建议和语音等功能 搜索行为。该文件传统上命名为searchable.xml和 必须保存在res/xml/project目录中


但我们仍然不知道是否必须创建xml文件夹,以及如何在res文件夹下手动创建xml目录,如res-xml将您的Car.xml放入xml文件夹我添加了从xml/Car.xml检索数据的示例代码
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

public class Main extends Activity {
    private static String APP_TAG = "tag";
    private TextView textView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        textView = (TextView) findViewById(R.id.textField);
        findViewById(R.id.readBtn).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                XmlPullParser parser = getResources().getXml(R.xml.cars);
                StringBuilder stringBuilder = new StringBuilder();
                try {
                    while (parser.next() != XmlPullParser.END_DOCUMENT) {
                        String name = parser.getName();
                        String position = null;
                        String brand = null;
                        if((name != null) && name.equals("car")) {
                            int size = parser.getAttributeCount();
                            for(int i = 0; i < size; i++) {
                                String attrName = parser.getAttributeName(i);
                                String attrValue = parser.getAttributeValue(i);
                                if((attrName != null) && attrName.equals("position")) {
                                    position = attrValue;
                                } else if ((attrName != null) && attrName.equals("brand")) {
                                    brand = attrValue;
                                }
                            }
                            if((position != null) && (brand != null)) {
                                stringBuilder.append(position + ", " + brand + "\n");
                            }
                        }
                        textView.setText(stringBuilder.toString());
                    }
                }catch(Exception e) {
                    Log.e(APP_TAG, e.getMessage());
                }
            }
        });
    }