-2

I have created an android application in that I want to display some Image data vertically in ListView.

How to make it possible ?

I tried using this code-

<LinearLayout
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="360dp"
    android:layout_above="@+id/relativeLayout2"
    android:layout_below="@+id/relativeLayout1"
    android:gravity="center"
    android:orientation="vertical" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="left|top"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="15dp"
        app:layout_gravity="fill_vertical"
        android:entries="@array/country_image_list" >
    </ListView>
</LinearLayout>
Anjali Pandya
  • 83
  • 2
  • 9

3 Answers3

0
public class ItemImagesAdapter extends BaseAdapter {

private Context context;
private ArrayList<String> paths;
private ImageLoader iml;

public ItemImagesAdapter(FragmentActivity activity, ArrayList<String> image_paths) {
    context = activity;
    paths = image_paths;
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(activity).build();
    ImageLoader.getInstance().init(config);
    iml = ImageLoader.getInstance();
}

@Override
public int getCount() {
    return paths.size();
}

@Override
public Object getItem(int position) {
    return paths.get(position);
}

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

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = LayoutInflater.from(context);
    if (convertView == null) {
        convertView = inflater.inflate(R.layout.list_item_image, parent, false);
    }
    String path = paths.get(position);
    ImageView image = (ImageView) convertView.findViewById(R.id.image1);
    iml.displayImage(path, image);
    return convertView;
}

}

take one more layout for list item as R.layout.list_item_image. here i am taking image loader to load the images from server. if you are getting images by means local...then set them directly

hope this may helps you

GvSharma
  • 2,632
  • 1
  • 24
  • 30
  • 2
    How this adapter source code matches OP requirement? It is basic code of adapter for any listview. – Manish Dubey Apr 16 '14 at 04:37
  • refer her comment in the question ...i asked her requirment..then the reply was this.."means Images are vertically scrolled in Listview.".... am i wrong...if yes kindly correct me.. – GvSharma Apr 16 '14 at 04:41
  • Where is code of horizontal scrolling in listview in above adapter code? It is just basic adapter code. – Manish Dubey Apr 16 '14 at 07:49
0

You can try to manage your requirement using TwoWayView for Horizontal scrolling of ListView items with Vertical scrolling. You can aslo check this demo for the same on github.

Manish Dubey
  • 4,206
  • 8
  • 36
  • 65
0

XML for first activity

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".FirstActivity" 
android:orientation="vertical">

<ListView 
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"></ListView>

</LinearLayout>

XML for row layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
 >


    <ImageView 
    android:id="@+id/myImage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    />


</LinearLayout>

Create this layouts and then using custom adapter class you can fill the images for each row in image view...Something like this

Custom Adapter class

public class customAdapter extends BaseAdapter {

ArrayList<HashMap<String, String>> al = new ArrayList<HashMap<String,String>>();
Activity activity;
private static LayoutInflater inflater = null;

public customAdapter(Activity a, ArrayList<HashMap<String, String>> al) {
    Log.e("check", "");
    activity = a;
    this.al = al;
    inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public int getCount() {
    // TODO Auto-generated method stub
     return al.size();
}

@Override
public Object getItem(int position) {
    // TODO Auto-generated method stub
    return position;
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

            imageLoader=new ImageLoader(activity.getApplicationContext());
    View vi=convertView;
    if(convertView==null)
    {
    vi = inflater.inflate(R.layout.row_layout, null);
    }
    ImageView myImage = (ImageView) vi.findViewById(R.id.myImage);

    imageLoader.DisplayImage(//your image from resource here),myImage);
    return vi;
}

}

Any problem in this you can follow the link of the tutorial I have mentioned in the comments...

Yogesh D
  • 1,663
  • 2
  • 23
  • 38