2017-05-24 17 views
0

私のリストビューの行に削除ボタンを表示しようとしています。しかし、デザイナーではボタンが表示されますが、デバッグやアプリケーションの実行時には表示されません。これは私のコードです。リストビューにイメージボタンが表示されない

アダプタ:

using System.Collections.Generic; 
using Android.App; 
using Android.Graphics; 
using Android.Views; 
using Android.Widget; 
using CardAppReal.Lib.Models; 
using Square.Picasso; 

namespace CardAppReal.Assets 
{ 
    public class ListAdapter : BaseAdapter<Card> 
    { 
     List<Card> items; 
     Activity context; 
     public ListAdapter(Activity context, List<Card> items) 
      : base() 
     { 
      this.context = context; 
      this.items = items; 
     } 
     public override long GetItemId(int position) 
     { 
      return position; 
     } 
     public override Card this[int position] 
     { 
      get { return items[position]; } 
     } 
     public override int Count 
     { 
      get { return items.Count; } 
     } 
     public override View GetView(int position, View convertView, ViewGroup parent) 
     { 
      var item = items[position]; 
      View view = convertView; 
      if (view == null) // no view to re-use, create new 
       view = context.LayoutInflater.Inflate(NavigationDrawerTest.Resource.Layout.CardSavedRowLayout, null); 
      view.FindViewById<TextView>(NavigationDrawerTest.Resource.Id.TextCardSavedList1).Text = item.name; 
      view.FindViewById<TextView>(NavigationDrawerTest.Resource.Id.TextCardSavedList2).Text = item.supertype; 
      view.FindViewById<TextView>(NavigationDrawerTest.Resource.Id.TextCardSavedList3).Text = item.set; 
      Picasso.With(context).Load(item.imageUrl).Into(view.FindViewById<ImageView>(NavigationDrawerTest.Resource.Id.CardSavedImage)); 
      var imgButton = view.FindViewById<ImageButton>(NavigationDrawerTest.Resource.Id.ImgButtonSaved); 
      view.SetBackgroundColor(Color.Argb(150, 153, 217, 234)); 
      return view; 
     } 
    } 
} 

の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="#FFDAFF7F" 
    android:padding="8dp"> 
    <ImageButton 
     android:id="@+id/ImgButtonSaved" 
     android:layout_width="70dp" 
     android:layout_height="70dp" 
     android:src="@drawable/delete" 
     android:layout_alignParentLeft="true" 
     android:gravity="center" /> 
    <LinearLayout 
     android:id="@+id/TextCardList" 
     android:orientation="vertical" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingLeft="10dip"> 
     <TextView 
      android:id="@+id/TextCardSavedList1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="#FF7F3300" 
      android:textSize="20dip" 
      android:textStyle="italic" /> 
     <TextView 
      android:id="@+id/TextCardSavedList2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="14dip" 
      android:textColor="#FF267F00" 
      android:paddingLeft="5dip" /> 
     <TextView 
      android:id="@+id/TextCardSavedList3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="14dip" 
      android:textColor="#FF267F00" 
      android:paddingLeft="5dip" /> 
    </LinearLayout> 
    <ImageView 
     android:id="@+id/CardSavedImage" 
     android:layout_width="100dp" 
     android:layout_height="150dp" 
     android:padding="10dp" 
     android:src="@drawable/icon" 
     android:layout_alignParentRight="true" /> 
</RelativeLayout> 

は、いくつかのことが、どれもショーを試してみました。 ImageViewは正常に表示されているように正常に表示されます。どこが間違っているのかわからない私はそれが私のアダプタにあると思うより多くのことをする必要があります単純にimgbuttonを宣言します。しかし、私はそれ以上のことをする必要があるか分からない。

+0

'LinearLayout'が' Button'と重なっていると仮定します。あなたの 'LinearLayout'に' android:layout_toRightOf = "@ + id/ImgButtonSaved"を追加し、それが役立つかどうかを見てください。 @Amylinnは役に立たなかった。 – yennsarah

+0

しかし、ありがとう! –

+0

ヒントとして、デフォルトの画像で画像ビューを確認し、ピカソを使用して削除すると、何が間違っているのかを知ることができるかもしれません。 –

答えて

0

私は最終的に私が間違ったアダプタを使用していることを認識していました...これは開発時間の大きな無駄でした。私は、他の人がこれを読んだときに、使用しているアダプターを二重チェックすることを願っています。

見ていただきありがとうございます!

関連する問題