我刚刚开始了一个新类,并且像我对其他几个没有问题的类所做的那样布置了 XML,但是我现在在这个类中遇到了一个非常奇怪的资源错误。
我有一个名为“edit”的 XML 布局,其中包含一个编辑文本、一个按钮和一个列表视图。出于某种原因,当我在课堂上输入我的列表视图引用时,我收到“无法解决”的错误,我真的不明白这一点,因为它在 XML 中明确定义。
目前,id 是这样引用的:
android:id="@android:id/listEdit"
此 ID 引用似乎使列表视图在布局中一起消失,给我以下错误:
NOTE: This project contains resource errors, so aapt did not succeed, which can cause rendering failures. Fix resource problems first.
Couldn't resolve resource @android:id/listEdit
这是我的“编辑”XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/txteditSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Type A Name To Edit;"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/inputNameEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="@+id/btnSearchEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Search" />
<ListView
android:id="@android:id/listEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
<ListView
android:id="@+id/listEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
还有我的编辑类:
package com.example.flybase2;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
public class edit extends ListActivity implements OnClickListener {
Button editSearch;
EditText nameEdit;
ListView editList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.edit);
// ERROR: Error on the 'listEdit'
editList = (ListView)findViewById(android.R.id.listEdit);
DBHandler DBedit = new DBHandler(this, null, null);
DBedit.open();
Cursor cursor = DBedit.getData();
startManagingCursor(cursor);
@SuppressWarnings("static-access")
String [] from = new String [] {DBedit.KEY_NAME, DBedit.KEY_TEL, DBedit.KEY_EMAIL, DBedit.KEY_COMMENTS};
int [] to = new int [] {R.id.txtNameSet, R.id.txtContactSet, R.id.txtEmailSet, R.id.txtCommentSet};
@SuppressWarnings("deprecation")
SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this, R.layout.searchagain, cursor, from, to);
editList.setAdapter(cursorAdapter);
editSearch = (Button) findViewById(R.id.btnSearchName);
nameEdit = (EditText) findViewById(R.id.inputName);
editSearch.setOnClickListener(this);
}
@Override
public void onClick(View clickedSearchButton) {
String searchedName = nameEdit.getText().toString();
editList = (ListView)findViewById(android.R.id.list);
DBHandler DBsearchRef = new DBHandler(this, null, null);
DBHandler search = new DBHandler(this, null, null);
search.open();
Cursor cursor = search.searchOnName(searchedName);
startManagingCursor(cursor);
@SuppressWarnings("static-access")
String [] from = new String [] {DBsearchRef.KEY_NAME, DBsearchRef.KEY_TEL, DBsearchRef.KEY_EMAIL, DBsearchRef.KEY_COMMENTS};
int [] to = new int [] {R.id.txtEditNameSet, R.id.txtEditNumSet, R.id.txtEditEmailSet, R.id.txtEditCommentsSet};
@SuppressWarnings("deprecation")
SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this, R.layout.setedit, cursor, from, to);
editList.setAdapter(cursorAdapter);
}
}
谁能明白为什么会这样,因为它让我发疯!