Android:实例化扩展ArrayAdapter的类
如何在Android中实例化Android:实例化扩展ArrayAdapter的类,android,android-layout,listview,android-studio,android-arrayadapter,Android,Android Layout,Listview,Android Studio,Android Arrayadapter,如何在Android中实例化ArrayAdapter类型的对象 private class LeDeviceListAdapter extends ArrayAdapter<LeScanRecord> 私有类LeDeviceListAdapter扩展了ArrayAdapter LeScanRecord也是一个类。公共类LeDeviceListAdapter扩展了ArrayAdapter{ public class LeDeviceListAdapter extends A
ArrayAdapter
类型的对象
private class LeDeviceListAdapter extends ArrayAdapter<LeScanRecord>
私有类LeDeviceListAdapter扩展了ArrayAdapter
LeScanRecord也是一个类。公共类LeDeviceListAdapter扩展了ArrayAdapter{
public class LeDeviceListAdapter extends ArrayAdapter<LeScanRecord> {
Context context;
public LeDeviceListAdapter(Context context, int itemResource, List<LeScanRecord> itemList ) {
super(context, itemResource, itemList);
this.context = context;
this.itemResource = itemResource;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (null == convertView) {
convertView = newView(parent);
// your functionality here
}
return
}
private View newView(ViewGroup parent) {
return LayoutInflater.from(context).inflate(itemResource, parent, false);
}
}
语境;
public-LeDeviceListAdapter(上下文上下文、int-itemResource、List-itemList){
超级(上下文、项目资源、项目列表);
this.context=上下文;
this.itemResource=itemResource;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
视窗座;
if(null==convertView){
convertView=newView(父级);
//你的功能在这里
}
返回
}
私有视图新建视图(视图组父视图){
返回LayoutFlater.from(上下文)。膨胀(itemResource,parent,false);
}
}
公共类LeDeviceListAdapter扩展了ArrayAdapter{
语境;
public-LeDeviceListAdapter(上下文上下文、int-itemResource、List-itemList){
超级(上下文、项目资源、项目列表);
this.context=上下文;
this.itemResource=itemResource;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
视窗座;
if(null==convertView){
convertView=newView(父级);
//你的功能在这里
}
返回
}
私有视图新建视图(视图组父视图){
返回LayoutFlater.from(上下文)。膨胀(itemResource,parent,false);
}
}
您可以创建ArrayAdapter的对象并将其用作ListView适配器:
ArrayAdapter<LeScanRecord> adapter = new ArrayAdapter<LeScanRecord>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, values);
ArrayAdapter=新的ArrayAdapter(此,
android.R.layout.simple_list_item_1,android.R.id.text1,值);
其中,values
是要在列表视图中显示的LeScanRecord
对象的列表
有关使用ArrayAdapter的更多信息,请学习
您还可以通过扩展BaseAdapter
,为列表组件(ListView、GridView、微调器等)创建自定义适配器,这更简单、更直接
我建议您学习另一篇优秀的文章,您可以创建ArrayAdapter对象并将其用作ListView适配器:
ArrayAdapter<LeScanRecord> adapter = new ArrayAdapter<LeScanRecord>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, values);
ArrayAdapter=新的ArrayAdapter(此,
android.R.layout.simple_list_item_1,android.R.id.text1,值);
其中,values
是要在列表视图中显示的LeScanRecord
对象的列表
有关使用ArrayAdapter的更多信息,请学习
您还可以通过扩展BaseAdapter
,为列表组件(ListView、GridView、微调器等)创建自定义适配器,这更简单、更直接
我建议您通过查看一些自定义listview示例来学习另一篇优秀的文章。您所需要做的就是定义正确的构造函数,并用它创建新对象。请查看一些自定义listview示例。您所需要做的就是定义正确的构造函数,然后用它创建新对象。谢谢。请告诉我答案。如果你觉得有用,谢谢。请告诉我答案。如果你觉得有用的话