0
ListViewにratingBarとテキストを表示するために、newViewメソッドとbindViewメソッドを使用してCursorAdapterを拡張するクラスを作成しようとしています。私の問題は、私は間違ったメソッドを実装しているので、プログラムがこのクラスまたはfilldataメソッドで実装の他の問題があるかもしれないので、プログラムがクラッシュすることです。私の質問は何ですか?私は他のtextviewsと一緒にリストビューでの評価バーを表示できるようにコードを書くための正しい方法はありますか?Notepad3クラスウィッヒからカーソルアダプタを使用してListViewと評価バーを表示する
package com.android.demo.notepad3;
import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.EditText;
import android.widget.RatingBar;
public class NoteA extends BaseAdapter{
private final LayoutInflater mInflater;
private EditText mTitleText;
private EditText mBodyText;
private RatingBar mRatingBar;
private NotesDbAdapter mDbHelper;
Context c1;
static Cursor c;
private static boolean autoRequery;
public NoteA(Context context, int layout, Cursor c, String[] from, int[] to) {
super(context, c, autoRequery);
mInflater = LayoutInflater.from(context);
c1=context;
this.c=c;
mDbHelper = new NotesDbAdapter(context);
mDbHelper.open();
}
@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
final View view = inflater.inflate(R.layout.notes_row, null);
mTitleText = (EditText) view.findViewById(R.id.title);
mBodyText = (EditText) view.findViewById(R.id.body);
mRatingBar= (RatingBar) view.findViewById(R.id.ratingbar);
mTitleText.setText(c.getString(
c.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE)));
mBodyText.setText(c.getString(
c.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)));
mRatingBar.setRating(c.getFloat(
c.getColumnIndexOrThrow(NotesDbAdapter.KEY_RATING)));
return view;
}
// @Override
//public void bindView(View view, Context context, Cursor cursor) {
//}
//@Override
//public View newView(Context context, Cursor cursor, ViewGroup parent) {
//final View view = mInflater.inflate(R.layout.notes_row, parent, false);
//bindView(view, context, cursor);
//return view;
//}
}
Filldata方法はLISTAを拡張するありがとうctivity
あなたがBaseAdapterを使用して、独自のカスタムリストビューを作成する必要がprivate void fillData() {
Cursor notesCursor = mDbHelper.fetchAllNotes();
startManagingCursor(notesCursor);
// Create an array to specify the fields we want to display in the list (only TITLE)
String[] from = new String[]{NotesDbAdapter.KEY_TITLE,NotesDbAdapter.KEY_BODY};
// and an array of the fields we want to bind those fields to (in this case just text1)
int[] to = new int[]{R.id.text1,R.id.text2};
//Now create a simple cursor adapter and set it to display
ListAdapter notes = new NoteA(this, R.layout.notes_row, notesCursor, from, to);
setListAdapter(notes);
}
...またshouldnクラスの拡張としてBaseAdapterの代わりにCursorAdapterを使用していますか? – Stefan
アプリがクラッシュしたときに発生するエラーをlogcatで確認してください –
コードを更新しました....今度はプログラムが実行されますが、何も返されません...プログラム自体にメモを追加しても私はとても疲れている – Stefan