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

مشکل با ArrayAdapter و همچنین ListView

Smkm79  10 سال پیش  10 سال پیش
0 0

سلام ، من از طریق دیتابیس چند تا اطلاعات رو داخل یک لیست ریختم به این صورت :

 List<Contact> contacts = db.getAllContacts();

و یک کاستوم ArrayAdapter درست کردم به این صورت : 

        class CustomArrayAdapter extends ArrayAdapter<Contact> {

        public CustomArrayAdapter(Context context, int resource) {
            super(context, resource);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = LayoutInflater.from(parent.getContext());
            View root = inflater.inflate(R.layout.row_item, parent, false);
            TextView itmLongUrl = (TextView) root.findViewById(R.id.itm_longUrl);
            TextView itmShortUrl = (TextView) root.findViewById(R.id.itm_shortUrl);
            TextView itmText = (TextView) root.findViewById(R.id.itm_text);
            List<Contact> contacts = db.getAllContacts();

            for (Contact cn : contacts){
                itmLongUrl.setText(cn.getName());
                itmShortUrl.setText(cn.getPhoneNumber());
                itmText.setText(cn.getText());
            }
            return root;
        }
    }

آمّا لیست ویو خالی نشون میده :( هیچ اروری حتی وارنینگی هم داخل لاگ کت نیست :(

کد کامل MainActivity : 

public class MainActivity extends Activity {

    ListView lst;
    DatabaseHandler db = new DatabaseHandler(this);

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        lst = (ListView) findViewById(R.id.listView);

        // Inserting Contacts
        Log.d("Insert: ", "Inserting ..");
        db.addContact(new Contact("YEK", "9100000000", "SomeDetail", 1));
        db.addContact(new Contact("DO", "9199999999", "EEEEEE", 0));
        db.addContact(new Contact("SE", "9533333333" , "Ajaba", 1));

        // Reading all contacts
        Log.d("Reading: ", "Reading all contacts..");
        List<Contact> contacts = db.getAllContacts();

        lst.setAdapter(new CustomArrayAdapter(this, R.layout.row_item));

        for (Contact cn : contacts) {
            String log = "Id: "+cn.getID()+" ,Name: " + cn.getName() + " ,Phone: " + cn.getPhoneNumber()
                    + " ,Text: " + cn.getText() + " ,Fav: " + cn.getFav();
        Log.d("Name: ", log);
        }
    }

    class CustomArrayAdapter extends ArrayAdapter<Contact> {

        public CustomArrayAdapter(Context context, int resource) {
            super(context, resource);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = LayoutInflater.from(parent.getContext());
            View root = inflater.inflate(R.layout.row_item, parent, false);
            TextView itmLongUrl = (TextView) root.findViewById(R.id.itm_longUrl);
            TextView itmShortUrl = (TextView) root.findViewById(R.id.itm_shortUrl);
            TextView itmText = (TextView) root.findViewById(R.id.itm_text);
            List contacts = db.getAllContacts();

            for (Contact cn : contacts){
                itmLongUrl.setText(cn.getName());
                itmShortUrl.setText(cn.getPhoneNumber());
                itmText.setText(cn.getText());
            }
            return root;
        }
    }
}

الان سه چهار روزه اعصابمو زیر و رو کرده ! کم کم دارم خسته میشم :( 

0 0
کسی نیست جواب بده؟؟ اساتید پس کجان؟ (10 سال پیش)
0 0
یعنی هیچ کی نمیدونه ؟؟ ای بابا مارو بگو از کیا پرسیدیم ! متأسفم حقیقتا !!! (10 سال پیش)
0 0
ببين، تو حلقه فوري كه كانتكتا ست تكست ميشن يه لاگ بزار م ببين چه تعداد حلقه فورت اجرا ميشه، هم ببين آيا مشخصاتي كه get ميشه رو واقعا get ميكنه؟ (10 سال پیش)
0 0
علیک سلام ... اولا smkm_79 جان عزیز ببین داداش اینجا کسی موظف نیست حتما و حتما جواب شما رو بده و شما رو فوری به جواب برسونه که اینقدر زود ناراحت میشید و برای بقیه متاسف میشید ... از این لینک برای دیتابیست کمک بگیر و از لیست ویو استاد هم استفاده کن ایشالا مشکلت حل میشه... لینک (10 سال پیش)
 برای این سوال پاسخی وجود ندارد.

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