Ralph Kesrouani
Ralph Kesrouani

Reputation: 47

List view for images - android mobile app

I'm developing a mobile app for android on eclipse, and i have a screen with multiple images that i can scroll down and pick anyone of them. it looks exactly like this

https://lh5.ggpht.com/X7rRzt2BLlXp_TTHGqT9Eg4MjadJpEzVoFhI9KJgUouCdqMBBIw3GCfjq7PejfYX7jE=h900-rw

How is this possible? is there a simple way for listing the images in that order and of the same size ? Any help is appreciated because i researched this and only found that "List Views" arent what i am looking for. Thanks for the help!

Upvotes: 1

Views: 304

Answers (4)

Samir Bhatt
Samir Bhatt

Reputation: 36

Try android:scaleType=fitToXY in your custom layout

Upvotes: 1

WoookLiu
WoookLiu

Reputation: 402

You should use ListView. The link: http://developer.android.com/reference/android/widget/ListView.html

Upvotes: 1

Maveňツ
Maveňツ

Reputation: 1

Try this way

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class LazyAdapter extends BaseAdapter {

    private Activity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader;

    public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
    }

    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.list_row, null);

        TextView title = (TextView)vi.findViewById(R.id.title); // title
        TextView artist = (TextView)vi.findViewById(R.id.artist); // artist name
        TextView duration = (TextView)vi.findViewById(R.id.duration); // duration
        ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image

        HashMap<String, String> song = new HashMap<String, String>();
        song = data.get(position);

        // Setting all values in listview
        title.setText(song.get(CustomizedListView.KEY_TITLE));
        artist.setText(song.get(CustomizedListView.KEY_ARTIST));
        duration.setText(song.get(CustomizedListView.KEY_DURATION));
        imageLoader.DisplayImage(song.get(CustomizedListView.KEY_THUMB_URL), thumb_image);
        return vi;
    }
}

enter image description here

Here is the link http://www.androidinterview.com/android-custom-listview-with-image-and-text-using-arrayadapter/

Upvotes: 0

SteBra
SteBra

Reputation: 4247

You should make a custom ListView cells. They would have only an image and a text view, which you can change regarding which cell you pick.

There is an excelent tutorial for this:

http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/

Upvotes: 0

Related Questions