Making clickable list of images - android

I want make a clickable and scrollable list of images. When image is clicked it should appear appropriate string in TextView.
I have list of Object which have images id and string id in itself:
public class MyClass implements Serializable {
private int imageId;
private int stringId;
//(...)
}
public ArrayList<MyClass> listOfObjects = new ArrayList<MyClass>();
How it is best to do? I do not know too much to go about it.
Thanks in advance.
PS: Sorry for my bad english.

You have to implement a custom list view. The list view shall consist of a custom layout, in which every line consists of a button. Then, you can assign each imageId to the buttons. Then, it can display the related text using the same index in the list.

Related

i have this two array and i have values i want to show data line by line like if i want to click on pushup at time it will shows pushup img &string

public class Exerice_des extends AppCompatActivity {
LinearLayout exerice_dec;
ArrayList<String> arrayList =new ArrayList<>();
Array arrayimage;
Array arraydes;
int ChestImage[] = {R.drawable.pushup,R.drawable.pullup,R.drawable.flatbenchpress,R.drawable.inclinedumbellpress,R.drawable.declinepress,R.drawable.inclinefly,R.drawable.chestdip,R.drawable.armbent};
int Chestdes[]= {R.string.pushup,R.string.pullup,R.string.flatbench,R.string.incline,R.string.decline,R.string.inclinefly,R.string.chestdip,R.string.armbent};
}
}
i want to show this data in one by one
Create a RecyclerView or ListView and the write a custom adapter for it.
To show the image on click either create a new activity or a custom dialog for it
For reference https://www.journaldev.com/10416/android-listview-with-custom-adapter-example-tutorial

implementing custom array adapter for multi dimensional array

So I want to display more than one text view in a list view but I have completely no clue about how to do this. The idea I am trying to implement is actually a list of music files loaded from a multi dimensional array such that
String musicFiles[][] = {{"TRACK NAME","ARTIST NAME"}};
so that within the same row the array adapter can display the "TRACK NAME" and below that "ARTIST NAME" but obviously the array adapter can not take a multi dimensional array and i have to implement a custom adapter and extend the array adapter class. Problem is I have no idea how to do this. Help!
Multidimensional array might not be the simplest solution. I would suggest creating a container class for all required pieces of information about the music file.
Something like this:
public class MusicFile {
public final String trackName;
public final String artistName;
public MusicFile(String trackName, artistName) {
this.trackName = trackName;
this.artistName = artistName;
}
}
An then use it inside an array:
MusicFile[] music;

Problems in integrating my android app

I am developing Splash screen,GridView, ListView and 4 other codes.
Since every item click in GridView namely Image,video,document and upload displays the same items in ListView(my code is like that) I am confused as to how to apply the loops in the onItemClick(AdapterView parent, View view, int position, long id) method so that i can display image code,video code,document code and uploading code in accordance with the items in GridView and ListView
To be very precise just go through the flow below
1.Image(Grid View)-----Onclick---->Item1(listview)--Onclick()-->Image Code
---->Item2(listview)--Onclick()-->Image Code
---->Item3(listview)--Onclick()-->Image Code
---->Item4(listview)--Onclick()-->Image Code
2.Video(Grid View)-----Onclick---->Item1(listview)--Onclick()-->Video Code
---->Item2(listview)--Onclick()-->Video Code
---->Item3(listview)--Onclick()-->Video Code
---->Item4(listview)--Onclick()-->Video Code
3.Document(Grid View)-----Onclick---->Item1(listview)--Onclick()-->Document Code
---->Item2(listview)--Onclick()-->Document Code
---->Item3(listview)--Onclick()-->Document Code
---->Item4(listview)--Onclick()-->DocumentCode
4.Upload(Grid View)-----Onclick---->Item1(listview)--Onclick()-->Upload Code
---->Item2(listview)--Onclick()-->Upload Code
---->Item3(listview)--Onclick()-->Upload Code
---->Item4(listview)--Onclick()-->UploadCode
Thanks in advance if anybody could help it would be fantastic
If your grid screen and list screen are seperate activities, then you can pass the "type" of the grid option that was selected by the user as an extra in the intent you are using to start the list activity. And then depending on this value, you can decide the action that is to be taken in the onItemClick.
Hope that helps.
Define the types for your operations. like,
public static final int OPTION_IMAGECODE = 1 ;
public static final int OPTION_VIDEOCODE = 2 ; ...etc
and a varaible to hold the type like, private int selectedGridOption ;
When user clicks on the grid option, populate the variable. Like,
selectedGridOption = OPTION_IMAGECODE ; if the user selectes the image type.
In your intent you use to start the list activity put this value as an extra. Like,
listActivityIntent.putExtra("Selected Option", selectedGridOption) ;
In you list activity you can retreive this value as,
getIntent().getIntExtra("Selected Option", *default_value_you_want*) ;

Large Complex List Of Items In Android

Take the following example screen:
This screen is displaying all current offers, these offers are dynamic.
What would be the best way of implementing the 'Offer' item? Should I use a ListView with a custom ListItem or is there a better solution to handling a list of complex items like this?
Any help appreciated.
Create an adapter with a list that contains a cell layout.
public class ListObject {
public int layout;
... other fields;
}
public class MyAdapter extends ArrayAdapter<ListObject>
and in the getview method, inflate the view that is needed for the offer.
public View getView(...) {
ListObject lo = getItem(position);
convertview = inflater.inflate(lo.layout, null);
}
is this what your trying to do? if not explain your question a bit more.

Android arrayadapter on spinner

I want to populate a spinner with some values from a List
The list is populated with objects
ArrayAdapter<PersonDetails> toStopAdapter = new ArrayAdapter<PersonDetails>(MoreTicketSalesActivity.this, R.layout.generic_spinneritem,
R.id.spinner_item_name, personDetails);
Spinner.setAdapter(toStopAdapter);
My PersonDetails class looks like this
private int id;
private int index;
private String name;
At the moment when i set the adapter the personDetails is full with data
But on my spinner is displayed some strange text "com.project.person ..."
What i do wrong?
Thanks
You're using a simple display for each element of the spinner. What does 'generic_spinneritem' look like?
The simple answer is to make sure your PersonDetails class overrides toString and returns the name (or whatever you want). Right now its showing a class name.
For more complicated row display, you'll need to create a custom adapter and override getView.

Categories

Resources