2014-03-31 43 views
0

我的應用程序包含數據庫與sqlite,我填寫我的數據庫,我想對它進行搜索, 所以我用自動完成,我把它在我的XML,我的應用程序工作正常,但是當我在我的autocomlete我的應用程序停止寫一封信!android.widget.LinearLayout不能轉換爲android.widget.TextView與sqlite

@Override 
public void bindView(View view, Context context, Cursor cursor) 
{ 
    String item = createItem(cursor);  
    ((TextView) view).setText(item);  
} 

@Override 
public View newView(Context context, Cursor cursor, ViewGroup parent) 
{ 
    final LayoutInflater inflater = LayoutInflater.from(context); 
    final TextView view = (TextView) inflater.inflate(R.layout.list_item, parent, false); // this is line number 33 


    String item = createItem(cursor); 
    view.setText(item); 
    return view; 
} 

list_item.xml:

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

所以請幫助我,我不知道在哪裏

我讓我的應用程序時,

03-31 17:54:02.846: E/AndroidRuntime(1210): java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView 
03-31 18:55:41.886: E/AndroidRuntime(16753): at com.example.oranmapbdd.StationAdapter.newView(StationAdapter.java:33) 

我的課得到這個錯誤完全是問題!

我試圖刪除我的R.java並清理我的項目,沒有任何改變!

+0

請出示您的xml文件 – l1nuxuser

+0

日Thnx ..做! – zinsaf

+0

AnswerBot已經回答了,所以祝你好運 – l1nuxuser

回答

1

請其更改爲

public View newView(Context context, Cursor cursor, ViewGroup parent) 
{ 
final LayoutInflater inflater = LayoutInflater.from(context); 
final LinearLayout view = (LinearLayout) inflater.inflate(R.layout.list_item, parent, false); 
AutoCompleteTextView tx = (AutoCompleteTextView)view.findViewbyid(R.id.filter); 

String item = createItem(cursor); 
tx.setText(item); 
return view; 
} 

@Override 
public void bindView(View view, Context context, Cursor cursor) 
{ 
String item = createItem(cursor); 
AutoCompleteTextView tx = (AutoCompleteTextView)view.findViewbyid(R.id.filter);  
tx.setText(item);  
} 
相關問題