You can create a "template" Activity with empty widgets displaying info about any object that fits the template. Simply, you set the text and content when you want (when user adds new object).
eg. I have this BrowserActivity where there is a ListView of Song objects. When user clicks on one the app gets the object from the list and puts it to the second "template" activity.
ListView list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_browser);
list = findViewById(R.id.song_item_list_view);
SongItemArrayAdapter adapter = new SongItemArrayAdapter(this, Generator.getSampleSongs());
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Song item = (Song) list.getItemAtPosition(position);
Intent intent = new Intent(BrowserActivity.this, SongViewActivity.class);
intent.putExtra("EXTRA_SONG_ID", item.getId());
intent.putExtra("EXTRA_ROOT_ACTIVITY", SongViewActivity.Roots.browserActivity.toString());
startActivity(intent);
}
});
}
and the template SongViewActivity
String rootActivity;
int songsID;
TextView title;
TextView text;
TextView author;
Song displayedSong;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_song_view);
title = findViewById(R.id.title_song_tv);
text = findViewById(R.id.tv_scrolling_song_text);
author = findViewById(R.id.author_song_tv);
songsID = getIntent().getExtras().getInt("EXTRA_SONG_ID");
rootActivity = getIntent().getExtras().getString("EXTRA_ROOT_ACTIVITY");
for(Song song : Generator.getSongs()){
if(song.getId() == songsID){
author.setText(song.getAuthor());
title.setText(song.getTittle());
text.setText(song.getText());
displayedSong = song;
}
}