java - 找不到符号方法 INFLATE ,android studio

标签 java android xml android-inflate

我的代码中有 2 个错误,第一个是使用 INFLATE 时出现的错误:

if(customerLayout == null){
                        //INFLATE the Customer Information View
                        LinearLayout leftLayout = (LinearLayout)findViewById(R.id.rightLayout);
                        View customerInfo = getLayoutInflater().INFLATE(R.layout.customerinfo, leftLayout, false);
                        leftLayout.addView(customerInfo);
                    }

INFLATE(R.layout.customerinfo, leftLayout, false);

此行有此错误:

Error:(134, 64) error: cannot find symbol method INFLATE(int,LinearLayout,boolean)
Note: Recompile with -Xlint:deprecation for details.

还有另一个错误:

Error:Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.
<小时/>

整个 Activity 代码:

import java.util.Calendar;
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SearchView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class SearchViewActivity extends Activity implements SearchView.OnQueryTextListener,
        SearchView.OnCloseListener {

    private ListView mListView;
    private SearchView searchView;
    private CustomersDbAdapter mDbHelper;

    private TextView inspectionDate;
    private TextView customerText;
    private TextView nameText;
    private TextView addressText;
    private TextView cityText;
    private TextView stateText;
    private TextView zipCodeText;

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

        searchView = (SearchView) findViewById(R.id.search);
        searchView.setIconifiedByDefault(false);
        searchView.setOnQueryTextListener(this);
        searchView.setOnCloseListener(this);

        mListView = (ListView) findViewById(R.id.list);
        inspectionDate = (TextView) findViewById(R.id.inspectionDate);
        displayDate();

        mDbHelper = new CustomersDbAdapter(this);
        mDbHelper.open();

        //Clean all Customers
        mDbHelper.deleteAllCustomers();
        //Add some Customer data as a sample
        mDbHelper.createCustomer("PIZZA1", "Pizza Hut", "1107 West Adams Boulevard", "", "Los Angeles", "CA", "90007");
        mDbHelper.createCustomer("PIZZA2", "Pizza Hut", "1562 West Pico Boulevard", "", "Los Angeles", "CA", "90015");
        mDbHelper.createCustomer("PIZZA3", "Pizza Hut", "718 South Los Angeles Street", "", "Los Angeles", "CA", "90014");
        mDbHelper.createCustomer("PIZZA4", "Pizza Hut", "2542 West Temple Street", "", "Los Angeles", "CA", "90026");
        mDbHelper.createCustomer("PIZZA5", "Pizza Hut", "4329 North Figueroa Street", "", "Los Angeles", "CA", "90065");
        mDbHelper.createCustomer("PIZZA6", "Pizza Hut", "4351 South Central Avenue", "", "Los Angeles", "CA", "90011");
        mDbHelper.createCustomer("SUB1", "Subway", "975 West Jefferson", "", "Los Angeles", "CA", "90007");
        mDbHelper.createCustomer("SUB2", "Subway", "2805 South Figueroa Street", "", "Los Angeles", "CA", "90007");
        mDbHelper.createCustomer("SUB3", "Subway", "198 South Vermont Avenue", "", "Los Angeles", "CA", "90004");
        mDbHelper.createCustomer("SUB4", "Subway", "504 West Olympic Boulevard", "", "Los Angeles", "CA", "90015");

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mDbHelper  != null) {
            mDbHelper.close();
        }
    }

    public boolean onQueryTextChange(String newText) {
        showResults(newText + "*");
        return false;
    }

    public boolean onQueryTextSubmit(String query) {
        showResults(query + "*");
        return false;
    }

    public boolean onClose() {
        showResults("");
        return false;
    }

    private void showResults(String query) {

        Cursor cursor = mDbHelper.searchCustomer((query != null ? query.toString() : "@@@@"));

        if (cursor == null) {
            //
        } else {
            // Specify the columns we want to display in the result
            String[] from = new String[] {
                    CustomersDbAdapter.KEY_CUSTOMER,
                    CustomersDbAdapter.KEY_NAME,
                    CustomersDbAdapter.KEY_ADDRESS,
                    CustomersDbAdapter.KEY_CITY,
                    CustomersDbAdapter.KEY_STATE,
                    CustomersDbAdapter.KEY_ZIP};

            // Specify the Corresponding layout elements where we want the columns to go
            int[] to = new int[] {     R.id.scustomer,
                    R.id.sname,
                    R.id.saddress,
                    R.id.scity,
                    R.id.sstate,
                    R.id.szipCode};

            // Create a simple cursor adapter for the definitions and apply them to the ListView
            SimpleCursorAdapter customers = new SimpleCursorAdapter(this,R.layout.customerresult, cursor, from, to);
            mListView.setAdapter(customers);

            // Define the on-click listener for the list items
            mListView.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    // Get the cursor, positioned to the corresponding row in the result set
                    Cursor cursor = (Cursor) mListView.getItemAtPosition(position);

                    // Get the state's CAPITAL from this row in the database.
                    String customer = cursor.getString(cursor.getColumnIndexOrThrow("customer"));
                    String name = cursor.getString(cursor.getColumnIndexOrThrow("name"));
                    String address = cursor.getString(cursor.getColumnIndexOrThrow("address"));
                    String city = cursor.getString(cursor.getColumnIndexOrThrow("city"));
                    String state = cursor.getString(cursor.getColumnIndexOrThrow("state"));
                    String zipCode = cursor.getString(cursor.getColumnIndexOrThrow("zipCode"));

                    //Check if the Layout already exists
                    LinearLayout customerLayout = (LinearLayout)findViewById(R.id.customerLayout);
                    if(customerLayout == null){
                        //INFLATE the Customer Information View
                        LinearLayout leftLayout = (LinearLayout)findViewById(R.id.rightLayout);
                        View customerInfo = getLayoutInflater().INFLATE(R.layout.customerinfo, leftLayout, false);
                        leftLayout.addView(customerInfo);
                    }


                    //Get References to the TextViews
                    customerText = (TextView) findViewById(R.id.customer);
                    nameText = (TextView) findViewById(R.id.name);
                    addressText = (TextView) findViewById(R.id.address);
                    cityText = (TextView) findViewById(R.id.city);
                    stateText = (TextView) findViewById(R.id.state);
                    zipCodeText = (TextView) findViewById(R.id.zipCode);

                    // Update the parent class's TextView
                    customerText.setText(customer);
                    nameText.setText(name);
                    addressText.setText(address);
                    cityText.setText(city);
                    stateText.setText(state);
                    zipCodeText.setText(zipCode);

                    searchView.setQuery("",true);
                }
            });
        }
    }

    private void displayDate() {

        final Calendar c = Calendar.getInstance();

        inspectionDate.setText(
                new StringBuilder()
                        // Month is 0 based so add 1
                        .append(c.get(Calendar.MONTH) + 1).append("/")
                        .append(c.get(Calendar.DAY_OF_MONTH)).append("/")
                        .append(c.get(Calendar.YEAR)).append(" "));
    }
}

这里是 customerinfo.xml 的内容

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/customerLayout" android:layout_width="match_parent"
    android:layout_height="wrap_content" android:orientation="vertical">
    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/customer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            style="@android:style/TextAppearance.Medium"
            android:paddingRight="5sp"/>

        <TextView
            android:id="@+id/name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/customer"
            style="@android:style/TextAppearance.Small" />

        <TextView
            android:id="@+id/address"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/name"
            style="@android:style/TextAppearance.Small" />

        <TextView
            android:id="@+id/city"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/address"
            style="@android:style/TextAppearance.Small"
            android:paddingRight="2sp"/>

        <TextView
            android:id="@+id/comma"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/address"
            android:layout_toRightOf="@id/city"
            style="@android:style/TextAppearance.Small"
            android:paddingRight="2sp"
            android:text=","/>

        <TextView android:id="@+id/state"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/address"
            android:layout_toRightOf="@id/comma"
            style="@android:style/TextAppearance.Small"
            android:paddingRight="2sp"/>

        <TextView android:id="@+id/zipCode"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/address"
            android:layout_toRightOf="@id/state"
            style="@android:style/TextAppearance.Small" />
    </RelativeLayout>
</LinearLayout>

最佳答案

Java 是一种区分大小写的语言。该方法是 inflate(),而不是 INFLATE()

关于java - 找不到符号方法 INFLATE ,android studio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29996241/

相关文章:

asp.net-mvc - ASP.NET MVC - 以 HTML 或 XML 形式返回数据

java - 使用 Java BigIntegers 在 RSA 中解密时,如何在原始数据的开头保留零字节?

java - 将 String 拆分并转换为 int

java - 如何确定给定 Maven 依赖项的来源?

java - 我可以通过常规 J​​ava main 方法从 Android 项目运行纯 Java 代码的子集吗?

android - 如何在 Smack 4.1 中的 XMPP 消息标签中添加自定义属性(昵称)

java - Eclipse 在启动时抛出 org.osgi.framework.BundleException

java - android studio 无法解析import com.google.android.gms.location.places.Place;

xml - 在 Twig 中打印 XML 的内容

Xmlstarlet,多个元素和日期排除