我有一個問題,目前我正在使用CursorTreeAdapter但是我想改變它使用任何其他數據不只是遊標,但說實話我不知道我該怎麼做,我認爲實施一些其他適配器然後重寫所需的方法?但是,有沒有人能以某種方式向我展示?我現在很困惑,不知道我該走什麼方向。 感謝您的幫助。自定義適配器執行
Q
自定義適配器執行
0
A
回答
0
您可以擴展的抽象類:BaseAdapterArrayAdapter。
0
你可以看到這個例子:
public class FeedAdapter extends BaseAdapter {
private ArrayList<FeedItem> items;
private LayoutInflater layoutInflater;
FeedAdapter(Context context, ArrayList<FeedItem> list, int bgColor){
items = list;
layoutInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return items.size();
}
@Override
public FeedItem getItem(int index) {
return items.get(index);
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row;
if (null == convertView) {
row = layoutInflater.inflate(R.layout.romanblack_feed_item, null);
} else {
row = convertView;
}
TextView title = (TextView) row.findViewById(R.id.romanblack_rss_title);
TextView pubdate = (TextView) row.findViewById(R.id.romanblack_rss_pubdate);
String titleString = items.get(position).getTitle();
title.setText(titleString);
if(items.get(position).getTextColor() != Color.TRANSPARENT){
title.setTextColor(items.get(position).getTextColor());
}else{
title.setTextColor(Color.DKGRAY);
}
pubdate.setText(items.get(position).getPubdate());
return row;
}
}
和佈局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/romanblack_feed_item"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFF">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/romanblack_rss_bg_feed"
android:orientation="vertical">
<TextView
android:text="Title"
android:id="@+id/romanblack_rss_title"
android:textSize="14sp"
android:textColor="#222"
android:layout_margin="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="2011-01-01"
android:id="@+id/romanblack_rss_pubdate"
android:textSize="10sp"
android:textColor="#666"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
+0
感謝您對我的例子。 – user2141889
相關問題
- 1. android:ListActivity,自定義適配器
- 2. 從自定義適配器
- 3. MvxGridView自定義適配器
- 4. Android自定義適配器
- 5. 自定義ListView適配器
- 6. MultiAutoTextView自定義適配器
- 7. 從自定義適配器
- 8. StickyGridHeaders自定義適配器
- 9. Android自定義適配器
- 10. 執行與自定義適配器的複選框
- 11. android studio自定義適配器OnClickListener
- 12. 圖庫的自定義適配器
- 13. 使用自定義適配器的ListView。
- 14. 爲ListView編寫自定義適配器
- 15. Breezejs自定義backingStore適配器
- 16. 實現自定義適配器
- 17. setActivityForResult()在自定義適配器類
- 18. 自定義適配器重複
- 19. Android中的自定義適配器
- 20. Increment/Decrement自定義ListView適配器
- 21. 自定義陣列適配器問題
- 22. Android - ListFragment和自定義適配器
- 23. AutoCompletetextview自定義適配器問題
- 24. ListView的自定義適配器
- 25. GridView的自定義視圖適配器
- 26. 的BizTalk自定義適配器
- 27. 自定義適配器notifyDataSetChanged不工作
- 28. 自定義列表適配器Xamarin.Android
- 29. Android:NullPointerException自定義ListView適配器
- 30. 如何使用自定義適配器
感謝您指出我了:) – user2141889