1

SimpleCursorAdapter を使用して sqlite からデータを読み取る ListView があり、テーブルには約 1000 行ありますが、アクティビティのリストを日付でフィルター処理したため、フィルター処理されたカーソルにはその特別な日の 2 行が含まれています。そのため、カスタムを追加したかった私のリストの行番号(_idを使用できません)。私が考えた解決策の1つはViewBinderでした。これが私のコードです:

adapter.setViewBinder(new ViewBinder() {
    public boolean setViewValue(View aView, Cursor aCursor, int aColumnIndex) {
        if (aColumnIndex == 0) {
            aCursor.moveToFirst();
            if(aCursor.moveToFirst()) {
                TextView textView = (TextView) aView;
                textView.setText("" + WeeklyListRowNumber);
                WeeklyListRowNumber = WeeklyListRowNumber + 1;
            }
            return true;
        }
        return false;
    }
});

List に 11 列があり、WeeklyListRowNumber が一番上に 1 で初期化されています。問題は、行番号が 7,8 になることですが、1 , 2 でなければなりません。この問題を解決するにはどうすればよいですか?

4

3 に答える 3

1

最後に、ViewBinderの問題を解決しました:

adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {

        public boolean setViewValue(View aView, Cursor aCursor, int aColumnIndex) {
            if (aColumnIndex == 0) {
                    TextView textView = (TextView) aView;
                    int CursorPos = aCursor.getPosition() + 1;
                    textView.setText(Integer.toString(CursorPos));

                return true;
             }

            return false;
        }});
于 2013-01-06T12:23:53.160 に答える
1
public View getView(int position, View convertView, ViewGroup parent) {
        View retval = null;

            retval = LayoutInflater.from(parent.getContext()).inflate(
                    R.layout.content, null);

            title = (TextView) retval.findViewById(R.id.contactName);
            number = (TextView) retval.findViewById(R.id.contactNumber);
            title.setText(text to display in list);
            number.setText(""+position);//add row number to list //fixed the variable
        }
于 2013-01-07T04:55:17.203 に答える
1

リストビューにアダプターを使用しているため、 getview で位置変数を取得できます。その位置 (int) を、ゼロ (0) から始まるカスタム リストの行番号として使用します。

必要に応じて設定してください...

于 2013-01-05T12:51:53.307 に答える