0
我想根據字符串值設置我的imageview。但圖像從未設置。請指導我,如果我在這裏做錯了。由於Android - 無法在自定義適配器中設置我的imageView
這裏是我的代碼:
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
getExpense expense = objects.get(position);
EventController controller = new EventController(ctx);
View view = convertView;
if (view == null) {
view = lInflater.inflate(R.layout.view_expense_entry, parent, false);
}
TextView expenseId = (TextView)view.findViewById(R.id.expenseId);
expenseId.setText(expense.getExpenseId());
TextView expenseName = (TextView)view.findViewById(R.id.expenseName);
expenseName.setText(expense.getExpenseName());
TextView expenseQuantity = (TextView)view.findViewById(R.id.expenseQuantity);
expenseQuantity.setText("Quantity : x" + expense.getExpenseQuantity());
ImageView expenseImage = (ImageView)view.findViewById(R.id.ivtype);
String expenseType = controller.getExpenseType(expenseId.getText().toString());
if (expenseType.equals("Food")){
expenseImage.setImageResource(R.drawable.food);
}
else if (expenseType.equals("Beverage")){
expenseImage.setImageResource(R.drawable.drink);
}
else if (expenseType.equals("Dessert")){
expenseImage.setImageDrawable(ctx.getResources().getDrawable(R.drawable.dessert));
}
else if (expenseType.equals("Set")){
expenseImage.setImageDrawable(ctx.getResources().getDrawable(R.drawable.set));
}
return view;
}
您確定您是否達到條件?您是在調試器中完成的,還是可以添加日誌語句?即:Log.i(「DEBUG」,費用類型)。 – wyoskibum
你可以發佈錯誤日誌嗎? – jasonflaherty
@jasonflaherty找不到錯誤。 – AndroidWorld12