简体   繁体   English

具有颜色和按钮的Android Listview

[英]Listview with color and button android

I need to customize this listview, I wonder how I could do to put the buttons and an identifier of different colors to distinguish them. 我需要自定义此列表视图,我想知道如何才能放置按钮和不同颜色的标识符来区分它们。

Anyone know how it could be the xml? 有人知道怎么可能是xml吗? and how it could change colors ?? 以及它如何改变颜色? is there any component in android? android中有任何组件吗? or I could use an imageview to the colors? 或者我可以使用imageview的颜色?

在此处输入图片说明

I appreciate your help. 我感谢您的帮助。

You should use a custom class, to create the Adapter for the List, and that class has to extend the BaseAdapter class. 您应该使用自定义类为列表创建适配器,并且该类必须扩展BaseAdapter类。 In this class, you have to implement the following methods: 在此类中,您必须实现以下方法:

  • public int getCount()
  • public Object getItem(int position)
  • public long getItemId(int position)
  • public View getView(int position, View convertView, ViewGroup parent)

In the last one, you can get a LayoutInflater , and load a view from .xml . 在最后一个中,您可以获取LayoutInflater并从.xml加载视图。 In that .xml , you can define the layout of one row. 在该.xml ,您可以定义一行的布局。 Here's an example from one of my projects: 这是我的一个项目的示例:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // menuItems is an ArrayList of Strings
    final String menu = menuItems.get(position);
    LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.list_mainmenu_row, null);
    TextView menuText = (TextView) view.findViewById(R.id.menuListRow_menuItem);
    menuText.setText(menu);
    return view;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM