Load image and text of each ITEM (ListView) in the same Activity

1

How can I make the text and the image of my ListView inside that Activity? (Each ITEM its image and text, not in all the same, obviously)

My code:

listViewPersonas.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

        Intent intent = new Intent(getApplicationContext(), prueba.class);


        startActivity(intent);
    }
});
    
asked by UserNameYo 04.01.2017 в 19:13
source

1 answer

2

I think what you ask could be resolved with Fragments

You can create an Activity that contains two fragments, a Fragment with the list and another with the details view and change from one to another through Fragments transactions.

To change between the list view and the detail view you would have to make a transaction between fragments so you should remove the lines from the onClick Intent and replace them with something similar to the following:

listViewPersonas.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

        // Create new fragment and transaction
        Fragment newFragment = new ExampleFragment();
        FragmentTransaction transaction = getFragmentManager().beginTransaction();

        // Replace whatever is in the fragment_container view with this fragment,
        // and add the transaction to the back stack
        transaction.replace(R.id.fragment_container, newFragment);
        transaction.addToBackStack(null);

       // Commit the transaction
       transaction.commit();
    }
});

Then I leave you the documentation of fragments where you can learn more in depth.

P.D: Is there a reason why you want to have it in the same Activity, instead of having it in two different Activities? I say it because it's easier to do it in two Activities.

    
answered by 04.01.2017 / 20:10
source