我剛剛開始了一個新類,並且已經放出了XML,因爲我已經和其他幾個類一起完成了,沒有問題,但是現在我得到了這個類的一個非常奇怪的資源錯誤。listview XML id issue
我有一個名爲'edit'的XML佈局,其中包含一個edittext,一個按鈕和一個listview。由於某種原因,當我在我的類中輸入listview refence時,我得到'無法解決'的錯誤。我真的不明白這一點,因爲它在XML中有明確的定義。
目前的ID被標記爲這樣:
android:id="@android:id/listEdit"
此ID refrence似乎讓列表視圖消失都聚集在佈局給我下面的錯誤:
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);
}
}
任何人都可以看到爲什麼這會發生,因爲它使我瘋狂!
機器人:ID/listEdit不存在。如果您使用的是listActivity,則需要使用android:id/list。 – njzk2