Red Virus
Red Virus

Reputation: 1707

Cannot resolve method 'settext(java.lang.String)'

Something weird that's happening over here, on item.settext(name);I' am getting Cannot resolve method 'settext(java.lang.String)'.

I' am creating app where the list view will be dynamically generated by the database results.

Layout

<?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="horizontal" >
    <ListView
        android:id="@+id/lvItems"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Study cursors"
        android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>

Method

public void bindView(View view, Context context, Cursor cursor) {
    ListView item = (ListView) view.findViewById(R.id.lvItems);
    String name = cursor.getString(cursor.getColumnIndexOrThrow("name"));
    item.settext(name);
}

public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view =  inflater.inflate(R.layout.dashboard_completed, container, false);
        myDB = null;
        try {
            File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath());
            File file = new File(dir, "database.db");
            myDB = SQLiteDatabase.openDatabase(file.toString(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS|SQLiteDatabase.OPEN_READONLY);

            String q = "SELECT * FROM companies ORDER BY name ASC";
            Cursor mCursor = myDB.rawQuery(q, null);

            // Find ListView to populate
            ListView lvItems = (ListView) view.findViewById(R.id.lvItems);

            // Setup cursor adapter using cursor from last step
            dashboardCursorAdaptor todoAdapter = new dashboardCursorAdaptor(getActivity().getApplicationContext(), mCursor);

            // Attach cursor adapter to the ListView
            lvItems.setAdapter(todoAdapter);

            myDB.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return view;
    }

Upvotes: 0

Views: 972

Answers (2)

Navneil Naicker
Navneil Naicker

Reputation: 3691

I can't see your full code. I don't know where you have defined your ListView. Alot of developers makes mistakes in this step. Remember that ListView and TextView will have different Layout.

If I have to give you a solution, then I would recommend to go and check if you have a ListView and another layout item_WHATEVER where you will define the TextView.

On bindView method reference the TextView.

Upvotes: 1

ligi
ligi

Reputation: 39549

ListView has no setText method - I think what you want there is a TextView ..

Upvotes: 1

Related Questions