0

I am trying to pass data from an intent to a listview but i get the "The constructor ArrayAdapter is undefined" Error. This is my code:

   public class Loglist extends Activity {

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.diary_edit);

    TextView Exe =(TextView) findViewById(R.id.txtName2);
    Exe.setText(getIntent().getExtras().getString("extraname"));

     populateListView1();

}

      private void populateListView1(){



          TextView Name1;
        Name1.setText(getIntent().getExtras().getString("extraname"));  

          ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(this,R.layout.loglist,Name1);


         ListView List =(ListView) findViewById(R.id.listViewdiary);
         List.setAdapter(adapter2);

      }
2
  • You cannot pass a single string into an ArrayAdapter constructor. It has to be a String[] or an List<String>. Commented Apr 20, 2016 at 22:44
  • 1
    Actually, they're trying to pass a TextView. Commented Apr 20, 2016 at 22:46

1 Answer 1

1

Buddy, you are trying to pass in an instance of TextView, whereas you are supposed to pass in String[]. So, declare an array of String that you want to pass in, something like this:

private void populateListView1(){

    TextView Name1;
    String string1 = getIntent().getExtras().getString("extraname");
    Name1.setText(string1);  

    String[] array = new String[]{string1};
    ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(this, R.layout.loglist, array);


     ListView List =(ListView) findViewById(R.id.listViewdiary);
     List.setAdapter(adapter2);

}
Sign up to request clarification or add additional context in comments.

Comments

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.