定制arrayadapter和布局与多个元素片段

编程入门 行业动态 更新时间:2024-10-28 20:21:04
本文介绍了定制arrayadapter和布局与多个元素片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的布局名为main_layout 有一个RelativeLayout的像TextView的至少两个元素和ImageView的里面。

My layout named main_layout has a RelativeLayout with at least two elements like Textview and Imageview inside it.

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 );

我的适配器类别:

My Adapter Class :

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;

}

public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { LayoutInflater inflater = ((Activity) context).getLayoutInflater(); convertView = inflater.inflate(R.layout.main_layout, parent, false); holder = new ViewHolder(); holder.idProfissao = (TextView) convertView.findViewById(R.id.textViewId); //holder.descProfissao = (TextView) convertView.findViewById(R.id.textDescProf); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } Test item = getItem(position); holder.idProfissao.setText(item.getId_prof()); **<=== BUG HERE** return convertView; }

调试适配器code我在得到线holder.idProfissao.setText(item.getId_prof());资源ID无法找到....

Debugging adapter code I got in the line holder.idProfissao.setText(item.getId_prof()); Resource id cannot be found....

推荐答案

该方法的setText()TextView的类它的重载要么使用字符串或重新$ P $在R.string形式psenting一个id整数.some_text。如果item.getId_prof()不返回一个id,那么你需要将其设置为文本之前,使它成为一个字符串:

The method setText() of the TextView class it's overloaded to either use a String or an integer representing an id in the form of R.string.some_text. If item.getId_prof() doesn't return an id then you need to make it a String before setting it as text:

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

更多推荐

定制arrayadapter和布局与多个元素片段

本文发布于:2023-06-05 11:32:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/518790.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   片段   布局   元素   arrayadapter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!