آموزش های این وب سایت به صورت رایگان در دسترس است. اطلاعات بیشتر
بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]

مشکل در ساخت ListView

hamid.j  10 سال پیش  10 سال پیش
0 0

سلام.طبق آموزش استاد پیش رفتم ولی وقتی که برنامه رو اجرا میکنم کرش میکنه و این خطا رو نشون میده

0 0
کدت رو بزار ببینیم چی نوشتی به نظر میرسه از اداپتر ست کردنت باشه (10 سال پیش)
0 0
کسی نیست جواب بده؟ (10 سال پیش)
 برای این سوال 1 پاسخ وجود دارد.
پاسخ به سوال 
hamid.j  10 سال پیش
0 0

این کدهای ActivityMain :

public class ActivityMain extends Activity {

    public ArrayList<StructNote> notes = new ArrayList<StructNote>();
    public ArrayAdapter          adapter;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ListView lstContent = (ListView) findViewById(R.id.lstContent);
        adapter = new AdapterNote(notes);
        lstContent.setAdapter(adapter);

        for (int i = 0; i < 10; i++) {
            StructNote note = new StructNote();
            note.title = "Title " + i;
            note.description = "Description " + i;
            note.done = false;
            notes.add(note);
        }
        adapter.notifyDataSetChanged();
    }
}

 

 

اینم کدهای AdapterNote :

public class AdapterNote extends ArrayAdapter<StructNote> {

    public AdapterNote(ArrayList<StructNote> array) {
        super(G.context, R.layout.adapter_notes, array);
    }


    private static class ViewHolder {

        public TextView txtTitle;
        public TextView txtDescription;
        public CheckBox chkDone;


        public ViewHolder(View view) {
            txtTitle = (TextView) view.findViewById(R.id.txtTitle);
            txtDescription = (TextView) view.findViewById(R.id.txtDescription);
            chkDone = (CheckBox) view.findViewById(R.id.chkDone);
        }


        public void fill(ArrayAdapter<StructNote> adapter, StructNote item, int position) {
            txtTitle.setText(item.title);
            txtDescription.setText(item.description);
            chkDone.setChecked(item.done);

        }

    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        StructNote item = getItem(position);
        if (convertView == null) {
            convertView = G.inflater.inflate(R.layout.adapter_notes, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.fill(this, item, position);
        return convertView;

    }
}

 

 

ببخشید دیر جواب دادم.


پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .