0
正如標題所示,我正試圖在列表視圖中添加一個額外的自定義行以允許更多的自定義。我目前有一個自定義行設置爲列表視圖,正如我們所知,它將不斷重複,取決於輸入的信息量。現在我想擴展列表視圖來顯示多個自定義行,我已經陷入調整我的代碼,並希望如果有人可以看看。如何添加一個額外的自定義行到列表視圖?
我提供了我當前設置的解釋。
首先,我們擁有視圖持有者本身,它可以在中間設置信息。
public class ViewHolderWine {
public ImageView wineImage;
public TextView wineName;
public TextView wineDes;
public TextView winePrice;
public void setDataIntoViewHolder (List_String listString){
wineImage.setImageResource(listString.getIcon_wine());
wineName.setText(listString.getWineName());
wineDes.setText(listString.getWinedes());
winePrice.setText(listString.getWinePrices());
}
其次,我們有我的List_String,在其中獲取getters和setter。
public class List_String {
int icon_wine;
String wineName;
String winedes;
String winePrices;
public List_String(int icon_wine, String wineName, String winedes, String winePrices) {
this.icon_wine = icon_wine;
this.wineName = wineName;
this.winedes = winedes;
this.winePrices = winePrices;
}
public String getWinePrices() {
return winePrices;
}
public void setWinePrices(String winePrices) {
this.winePrices = winePrices;
}
etc......
接下來我們有ListFragment
public class List extends ListFragment {
java.util.List<List_String> lst;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
listData();
// Adapter custom;
Adapter myAdapter = new Adapter(getActivity(), R.layout.custom_list, lst);
setListAdapter(myAdapter);
return super.onCreateView(inflater, container, savedInstanceState);
}
public void listData() {
lst = new ArrayList<List_String>();
lst.add(new List_String(R.drawable.thumb, etc....
最後,我再把所有的拼在一起使用適配器。
public class Adapter extends ArrayAdapter<List_String> {
List<List_String> lstWine;
LayoutInflater inflater;
public Adapter(Context context, int resource, java.util.List<List_String> objects) {
super(context, resource, objects);
lstWine = objects;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
ViewHolderWine viewholder;
if (view == null){
viewholder = new ViewHolderWine();
view = inflater.inflate(R.layout.custom_list, null);
viewholder.wineImage = (ImageView) view.findViewById(R.id.wineImage);
viewholder.wineName = (TextView) view.findViewById(R.id.wineName);
viewholder.wineDes = (TextView) view.findViewById(R.id.wineDes);
viewholder.winePrice = (TextView) view.findViewById(R.id.winePrice);
view.setTag(viewholder);
}else{
viewholder = (ViewHolderWine) view.getTag();
}
List_String list = lstWine.get(position);
viewholder.setDataIntoViewHolder(list);
return view;
}
嗎?或者你只是想要一些底部的行有不同的外觀? – kampangala
基本上有些行有不同的外觀,以便我可以混合搭配。 – Steven
它們是否包含相同類型的數據? – kampangala