我的适配器:
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class NewAdapter extends ArrayAdapter<Presenter> {
Context context;
List<Presenter> presenterList;
private LayoutInflater mmInflater;
public NewAdapter(Context context, List<Presenter> data) {
super(context, R.layout.listview_item_row_presenters);
mmInflater = LayoutInflater.from(context);
this.context = context;
this.presenterList = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View itemView = convertView;
if (itemView == null) {
itemView = mmInflater.inflate(R.layout.listview_item_row_presenters, parent, false);
}
Presenter currentPresenter = presenterList.get(position);
ImageView imageView = (ImageView)itemView.findViewById(R.id.imgIcon);
imageView.setImageBitmap(currentPresenter.getImage());
TextView titleText = (TextView) itemView.findViewById(R.id.txtTitle);
titleText.setText(currentPresenter.getName());
TextView descripText = (TextView) itemView.findViewById(R.id.txtAbout);
descripText.setText(currentPresenter.getInfo());
return itemView;
}
}
调用&amp;将适配器设置为ListView
private void populateListView(List<Presenter> presList) {
ArrayAdapter<Presenter> adapter = new NewAdapter(this.getBaseContext(), presList);
ListView list = (ListView) findViewById(R.id.listViewPres);
list.setAdapter(adapter);
}
我有Logcat输出,证明非数据为空或空,非错误或任何东西:/ 我只能猜测它与上下文有关的任何问题。充气机,但它让我不知道为什么
先谢谢你
答案 0 :(得分:2)
变化
super(context, R.layout.listview_item_row_presenters);
与
super(context, R.layout.listview_item_row_presenters, data); // add data
在构造函数句柄listItem大小中扩展ArrayAdapter
,super
时,需要将列表传递给构造函数方法
有关示例代码,您可以参阅第2.3节AndroidListView