Closed. This question is not reproducible or was caused by typos。它当前不接受答案。
想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
4年前关闭。
我的代码中有2个错误,第一个错误是使用INFLATE:
INFLATE(R.layout.customerinfo,leftLayout,false);
这行有这个错误:
和另一个错误:
整个活动代码:
这是customerinfo.xml的内容
想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
4年前关闭。
我的代码中有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.
整个活动代码:
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()
。
09-11 22:17