nanay
nanay

Reputation: 301

The constructor ArrayAdapter <string> is undefined

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

      }

Upvotes: 0

Views: 271

Answers (1)

Joel Min
Joel Min

Reputation: 3457

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

}

Upvotes: 1

Related Questions