Android: проблема с listView и getView-методом - PullRequest
0 голосов
/ 17 ноября 2018

Эй, ребята, я довольно новичок в программировании Android и у меня есть несколько вопросов.Я надеюсь, что кто-то может помочь.

Я использую код:

new ArrayAdapter<Customer> (this, android.R.layout.simple_list_item_multiple_choice,emptyListForInitialization) {...

Но я хочу использовать свой собственный макет, который я создал ("R.layout.custom_customer_layout").

Я могу использовать его, если изменит кодовую строку с помощью:

new ArrayAdapter<Customer> (this, android.R.layout.simple_list_item_multiple_choice,emptyListForInitialization)

с моим макетом ("R.layout.custom_customer_layout")

И УДАЛИТЕ КОД

View view =  super.getView(position, convertView, parent);

И ОБНОВЛЯЙТЕ раздел (код между / * ... * /) под ним.


Но я не получаю метод getView.

ПОЧЕМУ Я ДОЛЖЕН СДЕЛАТЬ ДВАЖДЫ В МОЙ ПЛАН?

Первый раз при создании нового ArrayList

Второй раз в методе getView ???


Это важная часть моего кода:

    private ListView myTestListView;

    private void initializeCustomerListView() {
        myTestListView = (ListView) findViewById(R.id.listview_customers);

        List<Customer> emptyListForInitialization = new ArrayList<>();

        ArrayAdapter<Customer> customerArrayAdapter = new ArrayAdapter<Customer> (
                this, android.R.layout.simple_list_item_multiple_choice,
                emptyListForInitialization) {

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                View view =  super.getView(position, convertView, parent);

                /*
                View view = getLayoutInflater().inflate(R.layout.custom_customer_layout,null);

                TextView textViewName = (TextView)convertView.findViewById(R.id.textView20);
                TextView textViewContact = (TextView)convertView.findViewById(R.id.textView21);
                TextView textViewMobile = (TextView)convertView.findViewById(R.id.textView25);

                textViewName.setText(this.getItem(position).getCustomerName());
                textViewContact.setText(this.getItem(position).getCounterpart());
                textViewMobile.setText(this.getItem(position).getMobilePhoneNumber());
                */
                return view;
            }
        };

        myTestListView.setAdapter(customerArrayAdapter);
    }
...