简体   繁体   中英

android.widget.LinearLayout cannot be cast to android.widget.TextView with sqlite

my app contain a database with sqlite , i filling my DB and i want to make a search on it , so i used the autocomplete , i put it in my XML , my app work fine but when i write a letter in my autocomlete my app stop !!

I get this error when making my 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)

my class :

    @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>

so please help me i don't know where is the problem exactly !!

i tried to delete my R.java and cleaning my project and nothing changed !!

Please change it to

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);      
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM