Customized ListView with TextView, TextView, RadioGroup in Android

前端 未结 2 876
悲&欢浪女
悲&欢浪女 2021-01-21 22:13

I\'m developing an application with ListView for Student Marklist creation.

In this application, the List have 10 students. There are four grades provided f

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-21 22:32

    You can use a class inheriting from ArrayAdapter, and overriding its getView() method.

    public class StudentAdapter extends ArrayAdapter {
    
    protected LayoutInflater inflater;
    
        public StudentAdapter(final Context context) {
            super(context, 0);
            inflater = (LayoutInflater) ((Context) context)
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }
    
        public View getView(int position, View convertView, ViewGroup parent) {
    
            // Note: You should optimize here with re-using convertView
    
            View rowView = inflater.inflate(R.layout.user_address_row_layout,
                    parent, false);
            TextView sNo = (TextView) rowView.findViewById(R.id.sNo);
            sNo.setText(getItem(position).number);
                // same for every field of the row
                // ...
    
            return rowView;
        }
    
     }
    

提交回复
热议问题