我的应用包含一个带有sqlite的数据库,我填充了我的数据库,我想对其进行搜索, 所以我使用自动完成功能,我把它放在我的XML中,我的应用程序工作正常,但是当我在我的autocomlete中写了一封信时,我的app停止!!
我在制作应用时遇到此错误
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)
我的班级:
@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>
所以请帮帮我,我不知道问题究竟在哪里!!
我试图删除我的R.java并清理我的项目而没有任何改变!!
答案 0 :(得分: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);
}