How to customize listview using baseadapter

前端 未结 5 521
陌清茗
陌清茗 2020-11-22 16:33

I wanna create a customized ListView like this:

\"TextView+ImageView

I think

5条回答
  •  日久生厌
    2020-11-22 16:57

    Create your own BaseAdapter class and use it as following.

     public class NotificationScreen extends Activity
    {
    
    @Override
    protected void onCreate_Impl(Bundle savedInstanceState)
    {
        setContentView(R.layout.notification_screen);
    
        ListView notificationList = (ListView) findViewById(R.id.notification_list);
        NotiFicationListAdapter notiFicationListAdapter = new NotiFicationListAdapter();
        notificationList.setAdapter(notiFicationListAdapter);
    
        homeButton = (Button) findViewById(R.id.home_button);
    
    }
    
    }
    

    Make your own BaseAdapter class and its separate xml file.

    public class NotiFicationListAdapter  extends BaseAdapter
    {
    private ArrayList> data;
    private LayoutInflater inflater=null;
    
    
    public NotiFicationListAdapter(ArrayList data)
    {
    this.data=data;        
        inflater =(LayoutInflater)baseActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    
    
    
    public int getCount() 
    {
     return data.size();
    }
    
    
    
    public Object getItem(int position) 
    {
     return position;
    }
    
    
    
    public long getItemId(int position) 
    {
        return position;
    }
    
    
    
    public View getView(int position, View convertView, ViewGroup parent) 
    {
    View vi=convertView;
        if(convertView==null)
    
        vi = inflater.inflate(R.layout.notification_list_item, null);
    
        ImageView compleatImageView=(ImageView)vi.findViewById(R.id.complet_image);
        TextView name = (TextView)vi.findViewById(R.id.game_name); // name
        TextView email_id = (TextView)vi.findViewById(R.id.e_mail_id); // email ID
        TextView notification_message = (TextView)vi.findViewById(R.id.notification_message); // notification message
    
    
    
        compleatImageView.setBackgroundResource(R.id.address_book);
        name.setText(data.getIndex(position));
        email_id.setText(data.getIndex(position));
        notification_message.setTextdata.getIndex(position));
    
        return vi;
    }
    
      }
    

    BaseAdapter xml file.

    
    
    
    
    
    
    
    
    
    
    
    
    
    

    Change it accordingly and use.

提交回复
热议问题