2016-11-12 14 views
0

ここで起きている変わったことがitem.settext(name);にあります。Cannot resolve method 'settext(java.lang.String)'です。メソッド 'settext(java.lang.String)'を解決できません

私は、リストビューがデータベース結果によって動的に生成されるアプリケーションを作成しています。

レイアウト

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

方法

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

答えて

1

を私は見ることができませんあなたの完全なコード。私はあなたがListViewをどこで定義したかわかりません。開発者の多くはこのステップで間違いを犯します。 ListViewTextViewは異なるLayoutを持つことに注意してください。

解決策が必要な場合は、ListViewと、TextViewを定義する別のレイアウトitem_WHATEVERがあるかどうかを確認することをおすすめします。

オンbindViewメソッド参照TextView

+0

ありがとうございます、あなたは正しいです。 ListView用とTextView用の2つのレイアウトを作成する必要がありました。それは素晴らしい仕事です。 –

+1

あなたを助けてくれてうれしいです。 –

1

ListViewコントロールが全くSetTextメソッドを持っていない - 私はあなたのTextViewがあると何をしたいと思います。..

+0

はい、正しいです。 –

関連する問題