Add an item to ListView (using Tabs)

54 Views Asked by At

I'm trying to add an item to a ListView which is in one of my 3 tabs, the object will be created on another activity and after creating I want to return to the Tab and there's already shown the object in the ListView, I wanted to do FindViewById in the java class of the Tab but this doesn't work, does anyone know how i could do this?

Code: Create Idea Activity

public class CreateIdeaActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_create_idea);


    final EditText title = (EditText) findViewById(R.id.ideaTitle);
    final EditText text = (EditText) findViewById(R.id.ideaText);
    final Button create = (Button) findViewById(R.id.btn_create);

    create.setOnClickListener(new View.OnClickListener(){

        @Override
        public void onClick(View view)
        {
            Idea idea = new Idea(title.getText().toString(),text.getText().toString(),"");
            Manager.AddObjectToIdeaList(idea); // Manager Class: List.add(idea)
        }
        });
}

One of my tabs (xml contains ListView) where I want to add items from the Manager-List to the ListView (findViewById does not work):

   public class ideastab_main extends Fragment{


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.activity_ideastab_main, container, false);
    return rootView;


}

}

0

There are 0 best solutions below