簡體   English   中英

具有顏色和按鈕的Android Listview

[英]Listview with color and button android

我需要自定義此列表視圖,我想知道如何才能放置按鈕和不同顏色的標識符來區分它們。

有人知道怎么可能是xml嗎? 以及它如何改變顏色? android中有任何組件嗎? 或者我可以使用imageview的顏色?

在此處輸入圖片說明

我感謝您的幫助。

您應該使用自定義類為列表創建適配器,並且該類必須擴展BaseAdapter類。 在此類中,您必須實現以下方法:

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

在最后一個中,您可以獲取LayoutInflater並從.xml加載視圖。 在該.xml ,您可以定義一行的布局。 這是我的一個項目的示例:

@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