gpt4 book ai didi

android - CardsLib ListView 未填充

转载 作者:行者123 更新时间:2023-11-29 20:46:43 31 4
gpt4 key购买 nike

我正在使用 Cardslib并尝试用自定义布局填充每张卡片。

我已设置好所有内容,但似乎无法正常工作。我遇到的问题是 CardListView 没有被填充。

这是我的代码:

public class ThemeActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_theme);

ArrayList<Card> cards = new ArrayList<Card>();
for (int i = 0; i < 8; i++) {
ColorCard card = new ColorCard(this);

switch (i) {
case 0:

card.mTitle = "Default Theme";
card.imageId = R.drawable.defaulttheme_thumb;

break;
case 1:

card.mTitle = "Cool Blue";
card.imageId = R.drawable.theme1_thumb;

break;
case 2:

card.mTitle = "Tropic Red";
card.imageId = R.drawable.theme2_thumb;

break;
case 3:

card.mTitle = "Distant Road";
card.imageId = R.drawable.theme3_thumb;

break;
case 4:

card.mTitle = "Simplistic";
card.imageId = R.drawable.theme4_thumb;

break;

case 5:

card.mTitle = "Coffe Time";
card.imageId = R.drawable.theme5_thumb;

break;

case 6:

card.mTitle = "Gloomy Orange";
card.imageId = R.drawable.theme6_thumb;

break;
case 7:
card.mTitle = "Dappled Purple";
card.imageId = R.drawable.theme7_thumb;

break;

case 8:

card.mTitle = "Vibrant Green";
card.imageId = R.drawable.theme8_thumb;

break;

}

cards.add(card);

}

CardArrayAdapter mCardArrayAdapter = new CardArrayAdapter(this, cards);

CardListView listView = (CardListView) this.findViewById(R.id.myList);
if (listView != null) {
listView.setAdapter(mCardArrayAdapter);
}

}
}

自定义卡片类:

public class ColorCard extends Card {

protected String mTitle;
protected int imageId;
TextView themeName;
ImageView themeThumb;

protected int count;

public ColorCard(Context context) {
this(context, R.layout.layout_cardview);
}

public ColorCard(Context context, int innerLayout) {
super(context, innerLayout);
init();
}

private void init() {

// Add ClickListener
setOnClickListener(new OnCardClickListener() {
@Override
public void onClick(Card card, View view) {
Toast.makeText(getContext(), "Click Listener card=" + count,
Toast.LENGTH_SHORT).show();
}
});
}

@Override
public void setupInnerViewElements(ViewGroup parent, View view) {

// Retrieve elements
themeName = (TextView) parent.findViewById(R.id.themeText);

themeThumb = (ImageView) parent.findViewById(R.id.themeThumb);

if (themeName != null)
themeName.setText(mTitle);

if (themeThumb != null)
themeThumb.setImageResource(imageId);

}



}

这是我的布局:

主 CardListView

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<it.gmariotti.cardslib.library.view.CardListView
android:id="@+id/myList"
android:layout_width="match_parent"
android:layout_height="match_parent"
card:list_card_layout_resourceID="@layout/layout_cardview" />

</LinearLayout>

layout_cardview

    <it.gmariotti.cardslib.library.view.CardViewNative xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card="http://schemas.android.com/apk/res-auto"
android:id="@+id/list_cardId"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
card:card_layout_resourceID="@layout/row_card" />

行卡:

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >


<ImageView
android:id="@+id/themeThumb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@null"
/>

<TextView
android:id="@+id/themeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingLeft="15dp"
android:textColor="@android:color/black"
android:textSize="20sp"
/>

</LinearLayout>

最佳答案

CardViewNative 中定义的card:card_layout_resourceID 应该定义卡片的全局布局。

应该是这样的:

card:card_layout_resourceID="@layout/native_card_thumbnail_layout"

检查 here了解更多信息。

您正在使用 (@layout/row_card) 内部布局。检查here了解更多信息。

关于android - CardsLib ListView 未填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30192661/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com