I have an activity that's runs an startactivityforresult and a onactivityresult. in the onactivityresult I can set the returned data to a variable and then put to add those variables to my arraylist, what I can't seem to do is use myAdapter.notifydatasetchanged() after this, just get a cannot resolve symbol. Is it because I created and declared the array in oncreate and the onactivityresult is not in oncreate?
Code snippets below...
Below done in oncreate
/*create array adapter and set to listview*/
final ArrayAdapter<String> myadapter = new ArrayAdapter<>(ListView_Activity.this, R.layout.simple_list_item_1, R.id.row_item_text_view, mylistarray);
final ListView mylistview = findViewById(R.id.mylistview);
mylistview.setAdapter(myadapter);
mylistarray.add("Test");
myadapter.notifyDataSetChanged();
final FloatingActionButton additembutton = findViewById(R.id.floatingActionButton);
additembutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent additem = new Intent(ListView_Activity.this, Create_Item_Activity.class);
startActivityForResult(additem, 1);
}
});
Then data retrieved here outside of oncreate;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if (requestCode == ADD_NEW_ITEM){
if (resultCode == Activity.RESULT_OK) {
tempdescr = data.getStringExtra("tempdescr");
tempname = data.getStringExtra("tempname");
mylistarray.add(tempdescr);
mylistarray.add(tempname);
myadapter.notifyDataSetChanged();
}
if (resultCode == Activity.RESULT_CANCELED) {
Toast replacewithcode = Toast.makeText(ListView_Activity.this, "replace with code", Toast.LENGTH_SHORT);
replacewithcode.show();
}
}
}