user1671523
user1671523

Reputation: 67

send listview data to another listview and activity

I have a problem with my android application.

I need to show all files from a folder which user 'chooses' from the listview. It works well if i do that in one activity, but i need to make it show files from the chosen folder in other activity listview.

For example:

We go list of folders in listview in activity A

For example folder "testfolder" contains text files so when i click on "testfolder" i need to show text files in listview of activity B

public class FolderActivity extends Activity {

EditText folderName;
ListView listView;
String CURRENT_FOLDER = Environment.getExternalStorageDirectory().toString()+"/AppicationTest";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_folder);


    Button button = (Button)findViewById(R.id.go);  


    createFolderOnStart();

    refreshDirectory();


    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        public void onItemClick(AdapterView<?> lista, View arg1, int position, long arg3) {
            Intent intent = new Intent(getApplicationContext(), ShowFiles.class);

            File file = new File(CURRENT_FOLDER + "/" + lista.getItemAtPosition(position));                                     

            if(file.canRead()){
                if(file.isDirectory()){
                    String[] list = file.list();

                    CURRENT_FOLDER += "/" + lista.getItemAtPosition(position);

                    listView.setAdapter(new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1, list)); 

                    intent.putExtra("files", list);

                }
            }
            startActivity(intent);
        }
    });
}

Here is the code of first activity.

What should i do to make files display in listview of second activity?

Upvotes: 1

Views: 532

Answers (1)

knvarma
knvarma

Reputation: 974

pass the full path of the current selected folder to activity B by passing through intent. Parse the same in B activity and show the files

Upvotes: 1

Related Questions