0

テキストスイッチャーが正しく機能していません.リストのアイコン(プラスアイコン)のいずれかをクリックするたびに...最後のテキストスイッチャー、つまりリストの最後の要素のテキストスイッチャーは、どのプラス記号をクリックしても.リストは正しく表示されています。データベースからデータを取得しました n 以下のコードはカスタム アダプター コードです。dataid は、その位置の要素の ID を示します。

private class SubjectDataList extends ArrayAdapter<String> {
        private TextSwitcher mSwitcher;
        List<String> names;
        Button btnadd;
        Typeface newsfont = Typeface.createFromAsset(getContext().getAssets(),
                "Adec.ttf");
        List<String> dataid = helper.getAllSubjectstsid();

        public SubjectDataList(Context context, int textViewResourceId,
                List<String> name) {
            super(context, textViewResourceId, name);
            // TODO Auto-generated constructor stub
            names = name;

        }

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return helper.getSubjectCount();
        }

        @Override
        public View getView(final int position, View convertView,
                ViewGroup parent) {

            View row = convertView;

            if (row == null) {
                row = getActivity().getLayoutInflater().inflate(
                        R.layout.subjectslist, parent, false);
                mSwitcher = (TextSwitcher)      row.findViewById(R.id.subjcount);
                btnadd = (Button) row.findViewById(R.id.addcountbtn);

                mSwitcher.setFactory(new ViewFactory() {

                    public View makeView() {
                        // TODO Auto-generated method stub
                        // create new textView and set the properties like
                        // color, size etc
                        TextView myText = new TextView(getActivity());
                        myText.setGravity(Gravity.TOP
                                | Gravity.CENTER_HORIZONTAL);
                        myText.setText("0");
                        myText.setTextSize(36);
                        myText.setTextColor(Color.GREEN);
                        myText.setTypeface(newsfont);
                        return myText;
                    }
                });
                // Declare the in and out animations and initialize them
                Animation in = AnimationUtils.loadAnimation(getActivity(),
                        R.anim.slide_in_up);
                Animation out = AnimationUtils.loadAnimation(getActivity(),
                        R.anim.slide_out_up);

                // set the animation type of textSwitcher
                mSwitcher.setInAnimation(in);
                mSwitcher.setOutAnimation(out);
                btnadd.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub

                        mSwitcher.setText(String.valueOf(helper
                                .getAllSubjectstscount(dataid.get(position))));
                    }
                });

                TextView text = (TextView) row.findViewById(R.id.subjectname);
                text.setTypeface(newsfont);
                text.setText(names.get(position));

            }
            return row;
        }

    }

これは、IDを取得するための私の関数です:

// getting subjects id
public List<String> getAllSubjectstsid() {
    List<String> list = new ArrayList<String>();
    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cur = db.rawQuery("Select " + colsubID + " from " + subjTable
            + " WHERE " + colsubjstudentid + "=" + getPos(), null);
    // looping through all rows and adding to list
    if (cur.moveToFirst()) {
        do {
            list.add(cur.getString(0));
        } while (cur.moveToNext());
    }
    // closing connection
    cur.close();
    db.close();

    return list;
}
4

1 に答える 1