定制arrayadapter和布局与多个元素片段 [英] fragment with custom arrayadapter and layout with multiple elements
问题描述
我的布局名为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和布局与多个元素片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!