Reputation: 954
Can I use one layout with 2 activities? I have an activity called "download.java" and one called "upload.java) and ONE layout called "main_site.xml".
"download.java" is the MainActivity It shows 2 buttons and an empty listview--> "Download", "Upload", "lv"
When I click on upload the second activity "upload" would start up which starts "main_site.xml" for second time and the listview would be filled with data.
Now I have 2 times "main_site.xml" one above the other... How can I just fill the listiview and not opening a "new" layout?
OnCreate in download.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_site);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
Button download = (Button)findViewById(R.id.cmd_download);
download.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
connectFTP("176.28.25.46");
listItems();
}
});
Button upload = (Button)findViewById(R.id.cmd_upload);
upload.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Intent myIntent = new Intent(MainSite.this, upload.class);
MainSite.this.startActivity(myIntent);
}
});
}
OnCreate in upload.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_site);
myPath = (TextView)findViewById(R.id.path);
root = Environment.getExternalStorageDirectory().getPath();
getDir(root);
}
Upvotes: 2
Views: 4837
Reputation: 11
Use Static array list to pass data from Upload to Download activity and just finish the Upload activity and based on conditions use the static arraylist in onResume() of Download activity
Upvotes: 1
Reputation: 1873
You should just update the ListView's contents, with the code in the same activity.
Upvotes: 2
Reputation: 11571
Yes , you can do. There is no reason why you can't do that. If your activity design layout is same in both these activity (or as many as you have in the app) you can use the same layout.xml file in different activity.
Upvotes: 1
Reputation: 2073
Yes you can, you just have to use <include>
as your tag, and again give an @+id/YOUR_NAME
to reuse the same layout.
Upvotes: 0