私は初心者です。アダプターを使用してカスタムリストビューを作成しましたが、アプリを実行しました。それは何かhelPを与える? // legendImage.setImageDrawable(image)のエラーです。ここカスタムリストビューのエラー
Here is picture of logcat file error クラスAdapterCustomlistViewある:
public class AdapterCustomListview extends ArrayAdapter<MoveData> {
private int resource;
private LayoutInflater inflater;
private Context context;
public AdapterCustomListview(Context ctx, int resourceId, List<MoveData> objects) {
super(ctx, resourceId, objects);
resource = resourceId;
inflater = LayoutInflater.from(ctx);
context = ctx;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = (LinearLayout) inflater.inflate(resource, null);
MoveData Legend = getItem(position);
TextView legendName = (TextView) convertView.findViewById(R.id.txtAppName);
legendName.setText(Legend.getName());
TextView legendBorn = (TextView) convertView.findViewById(R.id.txtCoin);
legendBorn.setText(Legend.getCoin());
ImageView legendImage = (ImageView) convertView.findViewById(R.id.imageView);
String uri = "drawable/" + Legend.getImage();
int imageResource = context.getResources().getIdentifier(uri, null, context.getPackageName());
//noinspection deprecation
Drawable image = context.getResources().getDrawable(imageResource);
legendImage.setImageDrawable(image); **//This row show error**
return convertView;
}
}
これはここホーム活性(MainActivity)
ctx = this;
List<MoveData> legendList = new ArrayList<MoveData>();
legendList.add(new MoveData("icon_dollar", "icon_dollar", "icon_dollar"));
legendList.add(new MoveData("icon_dollar", "icon_dollar", "icon_dollar"));
legendList.add(new MoveData("icon_dollar", "icon_dollar", "icon_dollar"));
legendList.add(new MoveData("icon_dollar", "icon_dollar", "icon_dollar"));
legendList.add(new MoveData("icon_dollar", "icon_dollar", "icon_dollar"));
legendList.add(new MoveData("icon_dollar", "icon_dollar", "icon_dollar"));
listViewItem = (ListView) findViewById(R.id.lvItem);
listViewItem.setAdapter(new AdapterCustomListview(ctx, R.layout.custom_layout_single, legendList));
// Click event for single list row
listViewItem.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
MoveData o = (MoveData) parent.getItemAtPosition(position);
Toast.makeText(Home.this, o.getName().toString(), Toast.LENGTH_SHORT).show();
}
});
}
あるクラスの移動データ
public class MoveData {
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCoin() {
return coin;
}
public void setCoin(String coin) {
this.coin = coin;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
private String name;
private String coin;
private String image;
public MoveData(String AppName, String Coin, String image) {
super();
this.name = AppName;
this.coin = Coin;
this.image = image;
}
}
コードフォーマットを整理し、エラーの内容を説明してください。 – rghome
私はこのページを使用していただきありがとうございます。 :(助けてもらえますか?pls – Monster
エラーとは何ですか?エラーメッセージをきれいな場所に入れ、適切にフォーマットしてください(例:見積もり機能付き) – rghome