Does anyone know what is my problem. I do not have any compile error messages however when i run the app it crashes and stops unexpectedly.
Here is my codes. Thank you in advance.
ListView l ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_final_project);
String arr[]={"Red","Green","Blue","Yellow","Cyan"};
l=(ListView) findViewById(R.id.listView1);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, arr);
l.setAdapter(adapter);
Button buttonOne = (Button) findViewById(R.id.button1);
buttonOne.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){
setContentView(R.layout.layout_save);
// setContentView(R.layout.activity_final_project);
//startActivity(new Intent("com.example.finalproject.layout_save"));
}
});
}
Give your ListView the appropriate id:
<ListView android:id="@android:id/list"
...
</ListView>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.