Android 具有自定义arrayadapter的片段和具有多个元素的布局

Android 具有自定义arrayadapter的片段和具有多个元素的布局,android,Android,名为main_layout的我的布局有一个RelativeLayout,其中至少包含两个元素,如Textview和Imageview public class SigninFragment extends Fragment { private List<Test> list= null; @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { sup

名为main_layout的我的布局有一个RelativeLayout,其中至少包含两个元素,如Textview和Imageview

public class SigninFragment extends Fragment {
            private List<Test> list= null;

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    Test tes= new Test ();
    tes.setId(1);
    tes.setDesc("descabc");
    list= new ArrayList<>();
    list.add(prof);

    tesListAdapter =
            new TesListAdapter(
                    rootView.getContext()
                    ,R.layout.list_row_adapter
                    ,list);

    autocompletetextview.setThreshold(3);
    autocompletetextview.setAdapter(tesListAdapter );
公共类SigninFragment扩展片段{
私有列表=空;
@凌驾
ActivityCreated上的公共无效(@Nullable Bundle savedinStateCState){
super.onActivityCreated(savedInstanceState);
测试tes=新测试();
setId(1);
tes.setDesc(“DESCAPC”);
列表=新的ArrayList();
增加(教授);
tesListAdapter=
新的TesListAdapter(
rootView.getContext()
,R.layout.list\u行\u适配器
,名单);
设置阈值(3);
setAdapter(tesListAdapter);
我的适配器类:

public class ProfissoesListAdapter extends ArrayAdapter<Test> { 
    private LayoutInflater inflater;
    private int resource;
private Context context;

public TesListAdapter(Context activity, int resource, List<Test> listaProf) {

super(activity, resource, listaProf);
this.resource = resource;
this.context = context;
公共类ProfissoesListAdapter扩展了ArrayAdapter{
私人充气机;
私有int资源;
私人语境;
公共列表适配器(上下文活动、int资源、列表){
超级(活动、资源、列表);
这个资源=资源;
this.context=上下文;
}

public View getView(int位置、视图转换视图、视图组父视图){
视窗座;
if(convertView==null){
LayoutInflater充气器=((活动)上下文)。getLayoutInflater();
convertView=充气机。充气(R.layout.main_布局,父级,false);
holder=新的ViewHolder();
holder.idProfissao=(TextView)convertView.findViewById(R.id.textViewId);
//holder.descProfissao=(TextView)convertView.findViewById(R.id.textDescProf);
convertView.setTag(支架);
}否则{
holder=(ViewHolder)convertView.getTag();
}
测试项目=获取项目(位置);
holder.idProfissao.setText(item.getId_prof())***TextView类的方法setText(),它被重载为使用字符串或以R.String.some_text形式表示id的整数。如果item.getId_prof()不返回id,则需要在将其设置为文本之前将其设置为字符串:

 holder.idProfissao.setText("" + item.getId_prof());

在xml中找到该id?请检查它是否存在。否则,请清理项目并运行它。我清理了项目,但没有结果…您收到错误消息:item.getId_prof()。你确定get方法返回的值正确吗?是的。它返回的值正确。我检查了它。错误:android.content.res.Resources$NotFoundException:String resource ID#0x1但它返回的是有效的ID。我只为测试硬编码了它:Test tes=new Test();tes.setId(1);tes.setDesc(“descabc”)@Al2x确实
getId_prof()
R.string.name_of_string
的形式返回id(此id将对应于
values/strings.xml
文件中声明的字符串)?如果您只返回任意整数,则需要在将其传递给setText()之前将其设置为字符串方法。也检查一下你的时间。你完全正确。我怎么能忘记这样一个封装的细节。
 holder.idProfissao.setText("" + item.getId_prof());