自定义ListView中的问题

时间:2018-09-21 12:33:23

标签: android listview baseadapter

我制作了一个自定义ListView,它显示了一个货币列表,其中(Image + TextView + LinearLayout必须定价:1用于出售货币,1用于购买货币)。 但不幸的是,该应用程序已崩溃,然后我打开LogCat来查看错误,但未发现任何错误。 我已附加文件以进行检查。从下一个软件包适配器开始

package adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.aboomar.bekamelnaharda.R;

import java.util.ArrayList;

import models.CurrencyModel;

public class CurrencyAdapter extends BaseAdapter {
Context context;
ArrayList<CurrencyModel> currencyModelArrayList;
CurrencyModel currencyModel = new CurrencyModel();

public CurrencyAdapter(Context context, ArrayList<CurrencyModel> 
currencyModelArrayList) {
this.context = context;
this.currencyModelArrayList = currencyModelArrayList;
}

public CurrencyAdapter() {
}


@Override
public int getCount() {
return currencyModelArrayList.size();
}

@Override
public CurrencyModel getItem(int position) {
return currencyModelArrayList.get(currencyModel.getId());
}

@Override
public long getItemId(int position) {
return getItem(currencyModel.getId()).getId();
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

LayoutInflater layoutInflater = (LayoutInflater) 
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = 
layoutInflater.inflate(R.layout.currency_list_item,parent,false);
currencyModel = getItem(currencyModel.getId());

ImageView imageViewCurrency = 
convertView.findViewById(R.id.imageCurrencyIv);
imageViewCurrency.setImageResource(currencyModel.getCurrencyImage());

TextView currencyNameTv = convertView.findViewById(R.id.nameCurrencyTv);
currencyNameTv.setText(currencyModel.getCurrencyTv());

TextView currencyBuyTv = convertView.findViewById(R.id.buyPriceTv);
currencyBuyTv.setText(currencyModel.getCurrencyPriceBuy());

TextView currencySellTv = convertView.findViewById(R.id.sellPriceTv);
currencySellTv.setText(currencyModel.getCurrencyPriceSell());


return null;
}
}

1 个答案:

答案 0 :(得分:0)

您正在getView方法中返回null,但应该返回convertView