我制作了一个自定义 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;
}
}