2012-04-05 24 views
0

お時間をありがとうございます。 RelativeLayoutを使用してリスト項目を表示しています。私は画像の右側にTextViewsのペアレントと束に整列した左の画像ボタンを持っています。 常に表示されるテキストビューは、オーダーの凡例.itemtitleオーダーのおまかせ.itempriceです。 CustomAdapterの条件に応じて、残りのテキストビューの表示を設定しています。 例えば、特別なリクエストが提供されている場合、アイテムオプションが要求の上に提供されている場合、アイテムオプションの上に追加アイテムが、最後にメインアイテムが追加されている場合は、 また、hereのように他のテキストビューのどれも表示されない場合、メインアイテムタイトルを一列に並べ替えることをお勧めします。 しかし、これは私がこの行レイアウトで得ているものではありません。特別なリクエストが提供されている場合、それは私が見ている唯一のテキストビューです。メインアイテムタイトルは表示されません。 私はそれができると確信しています、私は何かが欠けている必要があります。 あなたのお手伝いをよろしくお願いします。RelativeLayoutの属性alignWithParentIfMissingが期待した結果を出さない

ordersummaryrow.xml

ここ
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/listitem_background" 
    > 
<LinearLayout 
    android:id="@+id/ordersummaryrow.buttons" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_marginRight="5dp"> 
<ImageView 
    android:id="@+id/ordersummaryrow.delete" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/orderdelete" 
    android:layout_weight="1" /> 
<ImageView 
    android:id="@+id/ordersummaryrow.update" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/orderedit" 
    android:layout_weight="1" /> 
</LinearLayout> 
<TextView 
    android:id="@+id/ordersummaryrow.splrequest" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="@color/custom_black_color" 
    android:layout_toRightOf="@id/ordersummaryrow.buttons" 
    android:layout_alignParentBottom="true" /> 
<TextView 
    android:id="@+id/ordersummaryrow.itemoption" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="@color/custom_black_color" 
    android:text="Item Option" 
    android:layout_toRightOf="@id/ordersummaryrow.buttons" 
    android:layout_above="@id/ordersummaryrow.splrequest" 
    android:layout_alignWithParentIfMissing="true" 
    /> 
<TextView 
    android:id="@+id/ordersummaryrow.extraitem" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="@color/custom_black_color" 
    android:text="Extra Item Title" 
    android:layout_toRightOf="@id/ordersummaryrow.buttons" 
    android:layout_above="@id/ordersummaryrow.itemoption" 
    android:layout_alignWithParentIfMissing="true" 
    /> 
<TextView 
    android:id="@+id/ordersummaryrow.extraitemprice" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="@color/custom_black_color" 
    android:text="$" 
    android:layout_above="@id/ordersummaryrow.itemoption" 
    android:layout_alignParentRight="true" 
    android:layout_alignWithParentIfMissing="true" 
    /> 

<TextView 
    android:id="@+id/ordersummaryrow.itemtitle" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="@color/custom_black_color" 
    android:layout_above="@id/ordersummaryrow.extraitem" 
    android:layout_toRightOf="@id/ordersummaryrow.buttons" 
    android:layout_alignWithParentIfMissing="true" 
    android:gravity="center_vertical" 
    android:text="Item Title" /> 

<TextView 
    android:id="@+id/ordersummaryrow.itemprice" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="@color/custom_black_color" 
    android:text="$$" 
    android:layout_alignTop="@id/ordersummaryrow.itemtitle" 
    android:layout_alignParentRight="true" 
    /> 
</RelativeLayout> 

カスタムアダプタのすべてのあなたの...他)(IF()ステートメントで

@Override 
    public View getView(int position, View convertView, ViewGroup parent) 
    { 
     View row = convertView; 
     if(row == null) 
     { 
      LayoutInflater vi = (LayoutInflater)m_context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      try{ 
       row = vi.inflate(R.layout.ordersummaryrow, null); 
      } 
      catch(Exception e) 
      { 
       Log.i("SUBMENU", e.getMessage()); 
      } 
     } 
     OrderSummaryRowViewHolder holder = (OrderSummaryRowViewHolder)row.getTag(); 
     if(holder == null) 
     { 
      holder = new OrderSummaryRowViewHolder(row); 
      row.setTag(holder); 
     } 
     OrderedItem orderItem = m_orderedItem.get(position); 
     if (orderItem != null) 
     { 
      if(m_updateListener != null) 
       holder.m_updateBtn.setOnClickListener(m_updateListener); 
      else 
       Log.i("OrderSummaryRowAdapter", "Update Listener is not registered"); 

      if(m_deleteListener != null) 
       holder.m_deleteBtn.setOnClickListener(m_deleteListener); 
      else 
       Log.i("OrderSummaryRowAdapter", "Delete Listener is not registered"); 

      holder.m_titleTxt.setText(orderItem.get_orderItem().getName()); 
      holder.m_priceTxt.setText("$" + (String.valueOf(orderItem.get_orderItem().getPrice()))); 
      if(orderItem.get_extraItems().size() == 0) //No extra items added so hide corresponding text box 
      { 
       holder.m_extraItemTxt.setVisibility(View.GONE); 
       holder.m_extraItemPriceTxt.setVisibility(View.GONE); 
      } 
      else 
      { 
       StringBuilder sbItemName = new StringBuilder(); 
       StringBuilder sbItemPrice = new StringBuilder(); 
       for (SubMenu extraItem : orderItem.get_extraItems()) 
       { 
        sbItemName.append(extraItem.getName()); 
        sbItemName.append("\n"); 
        sbItemPrice.append("$" + (String.valueOf(extraItem.getPrice()))); 
        sbItemPrice.append("\n"); 
       } 
       holder.m_extraItemTxt.setText(sbItemName); 
       holder.m_extraItemPriceTxt.setText(sbItemPrice); 
      } 

      if(orderItem.get_options().size() == 0) 
       holder.m_optionTxt.setVisibility(View.GONE); 
      else 
      { 
       StringBuilder sbOption = new StringBuilder(); 
       for (ItemOption option : orderItem.get_options()) 
       { 
        sbOption.append(option.getName()); 
        sbOption.append("\n"); 
       } 
       holder.m_optionTxt.setText(sbOption); 
      } 

      if(orderItem.getspecialRequest() != null && 
        orderItem.getspecialRequest().length() > 0) 
       holder.m_splRequestTxt.setText(orderItem.getspecialRequest()); 
      else 
       holder.m_splRequestTxt.setVisibility(View.GONE); 

     } 
     return row; 
    } 
+0

動作するか確認してください?もしそうなら、誰がgetViewを気にしますか?)その混乱は...全体のポストはちょっと奇妙なものです。あなたが達成しようとしているレイアウトの種類を記述すると、素早く答えを得るでしょう。たとえば塗料で汚れたビットマップを描きます。 –

答えて

0

、setVisibilityを追加でgetViewメソッド()(View.VISIBLE)でありますステートメント。たとえば、

if(orderItem.getspecialRequest() != null && 
       orderItem.getspecialRequest().length() > 0){ 
      holder.m_splRequestTxt.setVisibility(View.VISIBLE); 
      holder.m_splRequestTxt.setText(orderItem.getspecialRequest()); 
     }else{ 
      holder.m_splRequestTxt.setVisibility(View.GONE); 
     } 

他のすべてのケースで同様です。

更新

このコードを試してみて、それがUIについてです

@Override 
public View getView(int position, View convertView, ViewGroup parent) 
{ 
    View row = convertView; 
    if(row == null) 
    { 
     LayoutInflater vi = (LayoutInflater)m_context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     try{ 
      row = vi.inflate(R.layout.ordersummaryrow, null); 
     } 
     catch(Exception e) 
     { 
      Log.i("SUBMENU", e.getMessage()); 
     } 
    } 
    OrderSummaryRowViewHolder holder = (OrderSummaryRowViewHolder)row.getTag(); 
    if(holder == null) 
    { 
     holder = new OrderSummaryRowViewHolder(row); 
     row.setTag(holder); 
    } 
    OrderedItem orderItem = m_orderedItem.get(position); 
    if (orderItem != null) 
    { 
     if(m_updateListener != null) 
      holder.m_updateBtn.setOnClickListener(m_updateListener); 
     else 
      Log.i("OrderSummaryRowAdapter", "Update Listener is not registered"); 

     if(m_deleteListener != null) 
      holder.m_deleteBtn.setOnClickListener(m_deleteListener); 
     else 
      Log.i("OrderSummaryRowAdapter", "Delete Listener is not registered"); 

     if(orderItem.getspecialRequest() != null && 
       orderItem.getspecialRequest().length() > 0) 
      holder.m_splRequestTxt.setText(orderItem.getspecialRequest()); 
     else 
      holder.m_splRequestTxt.setVisibility(View.GONE); 

     if(orderItem.get_options().size() == 0) 
      holder.m_optionTxt.setVisibility(View.GONE); 
     else 
     { 
      StringBuilder sbOption = new StringBuilder(); 
      for (ItemOption option : orderItem.get_options()) 
      { 
       sbOption.append(option.getName()); 
       sbOption.append("\n"); 
      } 
      holder.m_optionTxt.setText(sbOption); 
     } 

     if(orderItem.get_extraItems().size() == 0) //No extra items added so hide corresponding text box 
     { 
      holder.m_extraItemTxt.setVisibility(View.GONE); 
      holder.m_extraItemPriceTxt.setVisibility(View.GONE); 
     } 
     else 
     { 
      StringBuilder sbItemName = new StringBuilder(); 
      StringBuilder sbItemPrice = new StringBuilder(); 
      for (SubMenu extraItem : orderItem.get_extraItems()) 
      { 
       sbItemName.append(extraItem.getName()); 
       sbItemName.append("\n"); 
       sbItemPrice.append("$" + (String.valueOf(extraItem.getPrice()))); 
       sbItemPrice.append("\n"); 
      } 
      holder.m_extraItemTxt.setText(sbItemName); 
      holder.m_extraItemPriceTxt.setText(sbItemPrice); 
     } 

     holder.m_titleTxt.setText(orderItem.get_orderItem().getName()); 
     holder.m_priceTxt.setText("$" + (String.valueOf(orderItem.get_orderItem().getPrice()))); 

    } 
    return row; 
} 
+0

レイアウトでは、デフォルトで表示されます。 GetViewでは、私は条件に基づいてそれを隠しています。それでも私は、可視性をコードでVisibleに設定してショットを与えました。それは仕事をしなかった。 –

+0

Plzコードをチェックして動作するか確認してください – Shubhayu

+0

コードを反転することで論理的な理由は見られません(最初にsplリクエストを初期化し、最後にタイトルを初期化します)。私は試してみましたが、まだ問題を解決していませんでした。 –

関連する問題