Working with images in Android Studio

1

I wonder if there is a way to work with images on android. I have a List View, in this list I have several categories. When the user selects this category, I would like to load all images related to this category. But I do not know how to do this, I'm using fragments. I have an xml file with the list view and another one with the fragment where the images would appear.

This is the main class:

public class MainActivity extends FragmentActivity {
FragmentManager fm = getSupportFragmentManager();
ListView listItemView;

String[] listaCategorias = new String[]{"INÍCIO", "RESPOSTAS","PERGUNTAS","ALFABETO","ALMOÇO","BEBIDAS", "COMO ESTOU ME SENTINDO",
        "EU QUERO","FAMILIA", "FRUTAS", "HIGIENE FEMININA", "HIGIENE MASCULINA","INFORMÁTICA", "LEGUMES", "MANICURE",
        "MAQUIAGEM","MUSICAS", "NUMERAIS","ONDE ESTÁ?", "SENTIMENTOS", "TAMANHOS", "VERDURAS"};


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    final Fragment1 fragment1 = (Fragment1) fm.findFragmentById(R.id.fragment1);
    listItemView = (ListView) findViewById(R.id.listView1);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, listaCategorias);
    listItemView.setAdapter(adapter);

    listItemView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Toast.makeText(MainActivity.this, listaCategorias[position], Toast.LENGTH_SHORT).show();
            switch (position){
                case 1:


            }
        }
    });

}

And this is the class fragment, in which the images would appear:

public class Fragment1 extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup conteiner, Bundle saveInstanceState) {

    View view = inflater.inflate(R.layout.layout_frag_1, conteiner, false);
    /*ImageView  imageView   = null;
    imageView.findViewById( R.id.imageView ) ;

    Glide . with ( this )
            . load ( "http://goo.gl/gEgYUd" )
            . into ( imageView ) ;*/
    return (view);

}
    
asked by anonymous 19.10.2016 / 20:22

1 answer

0

I do not know if I understand your question. But have you considered creating an object that has the reference of the image and the reference of the category? With this you could sort or filter according to the objects.

class Foo {
     private int imageRef;
     private int categoryRef;
     ...
}

Then you could pass the array of objects to the ListView, and you would also have to create a custom ArrayAdapter. I hope your doubt has been this flws.

    
20.10.2016 / 00:13