0
我是新的Android開發人員,實際上我是網絡開發人員。問題類似於html + css類。Android設計實踐 - 開關視圖
在我的應用程序中,我有簡單的listView,自定義行視圖。對於不同的行狀態,我需要切換行的許多子元素,如顏色,背景顏色,某些元素的可見性。
我可以在我的CustomArrayAdapter的代碼中執行此操作。但它看起來很髒。
我該如何做到「美麗」?有類似於HTML中的類的android API嗎?
public View getView(int position, View convertView, ViewGroup parent) {
// ...
Integer items_count = merc.getItemsCount(); String item_count_label = "";
if(0 < items_count){
item_count_label = String.valueOf(items_count);
} else {
item_count_label = "";
}
countTextView.setText(item_count_label);
return rowView;
}
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item label"
android:focusable="false"
android:textSize="18dp"
android:textIsSelectable="true">
</TextView>
<TextView
android:id="@+id/profit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="12dp"
android:textColor="#00aa00"
android:layout_weight="1"
android:layout_marginLeft="15px">
</TextView>
<TextView
android:id="@+id/count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6"
android:textSize="18dp" >
</TextView>
你能顯示你的代碼嗎? – Raptor
現在很簡單。 https://github.com/Kein1945/LumiRoMerchantsAndroid。 文件src/com/lumiro/merchantmonitor/view/MerchantArrayAdapter.java 和res/layout/merchant_row.xml。但後來我需要添加更多元素。 – Kein
請在問題中粘貼相關的代碼,而不僅僅是一個鏈接。 – Raptor