我正在尝试将数据从intent传递到listview,但我得到“构造函数ArrayAdapter未定义”错误。 这是我的代码:
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);
}
答案 0 :(得分:1)
Buddy,您正在尝试传递TextView
的实例,而您应该传入String[]
。因此,声明要传入的String
数组,如下所示:
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);
}