0

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

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

4
  • find that id in your xml? check if it exists or not. otherwise clean project and run Commented Sep 22, 2015 at 17:14
  • it exists. I cleaned up project but with no results... Commented Sep 22, 2015 at 17:15
  • you are getting error her: item.getId_prof(). are you sure your get method returns the correct value? Commented Sep 22, 2015 at 17:17
  • yep. its returning the correct value. Ive inspected it. Error : android.content.res.Resources$NotFoundException: String resource ID #0x1 Commented Sep 22, 2015 at 17:20

1 Answer 1

2

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());
Sign up to request clarification or add additional context in comments.

3 Comments

but its returning a valid id. I hardcoded it only for tests : Test tes= new Test (); tes.setId(1); tes.setDesc("descabc");
@Al2x Does getId_prof() return an id in the form of R.string.name_of_string(this id will correspond to a string declared in the values/strings.xml file)? If you just return an arbitrary integer then you need to make it a string before passing it to the setText() method. Also check developer.android.com/guide/topics/resources/…
TY for your time. you are totally right. How could I forget a encapsulated detail like this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.