Is it possible to make the ListView
horizontally? I have done this using a gallery view, but the selected item comes to the center of the screen automatically. I don't want the selected item at the same spot I clicked. How can I rectify this problem? My idea was to set the ListView
with a horizontal scroll. Share your idea?
-
1use [this](http://stackoverflow.com/questions/22538993/how-to-change-backgroung-color-when-click-on-horizontal-listview-items-in-androi) link of my post to create Horizontal listView I hope it will help you. – Faiz Anwar Mar 21 '14 at 10:25
-
2@Indra that blog u mentioned has been removed – Animesh Mangla Dec 27 '15 at 13:05
-
You can check this example http://thedeveloperworldisyours.com/android/horizontal-listview-on-android/ – Cabezas Mar 14 '16 at 16:54
19 Answers
As per Android Documentation RecyclerView
is the new way to organize the items in listview and to be displayed horizontally
Advantages:
- Since by using Recyclerview Adapter, ViewHolder pattern is automatically implemented
- Animation is easy to perform
- Many more features
More Information about RecyclerView
:
Sample:
Just add the below block to make the ListView
to horizontal from vertical
Code-snippet
LinearLayoutManager layoutManager= new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL, false);
mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(layoutManager);

- 13,575
- 26
- 81
- 144

- 42,072
- 54
- 195
- 297
-
1This will be the best solution if issues with LayoutManager are fixed by google. https://code.google.com/p/android/issues/detail?id=74772 – Ponsuyambu Jun 15 '15 at 17:53
-
to build a simple recycler view, use this example: http://www.android-examples.com/android-simple-recyclerview-example-tutorial/ – Matcoil Nov 17 '16 at 15:28
-
2
-
In contrast to other adapter-backed views such as ListView or GridView, RecyclerView allows client code to provide custom layout arrangements for child views. These arrangements are controlled by the RecyclerView.LayoutManager. A LayoutManager must be provided for RecyclerView to function. – Yohanim Feb 06 '19 at 05:42
-
RecyclerView still can't handle clicks on items (don't mention RecyclerView.Selection class) as good and easy as ListView - that's one of the few reasons why I think RecyclerView isn't the best answer for this question. – Edward Quixote Nov 04 '19 at 17:39
-
Question was asked for ListView but the answer is provided for Recycle View, i think we should stick to the question. – Sachin Puri Nov 06 '22 at 07:36
Paul doesn't bother to fix bugs of his library or accept users fixes. That's why I am suggesting another library which has similar functionality:
https://github.com/sephiroth74/HorizontalVariableListView
Update: on Jul 24, 2013 author (sephiroth74) released completely rewritten version based on code of android 4.2.2 ListView. I must say that it doesn't have all the errors which previous version had and works great!

- 7,126
- 2
- 35
- 49
-
2This should be an accepted answer, 'cause this HorizontalVariableListView is much more advanced than Paul's one. For example it has an appropriate method to select position in a list, Paul's one has "TODO: implement someday" in it's place. – Yan.Yurkin Sep 24 '13 at 07:03
-
5
-
1sephiroth74's HorizontalVariableListView is exactly what you hope it to be: A copy of the ListView from the android source code with *all* of the methods updated to move horizontally rather than vertically. I haven't run into any issues yet. Thank you so much for directing me there, Malachiasz! – SilithCrowe Feb 20 '14 at 16:09
-
well wrap_content to listview is still not supported in this lib – Kalpesh Lakhani Jul 28 '14 at 09:59
-
Is anyone able to figure out how to use wrap_content for the layout_height? it messes everything when wrap_content is used – Snake Jan 13 '15 at 23:39
@Paul answer links to a great solution, but the code doesn't allow to use onClickListeners on items children (the callback functions are never called). I've been struggling for a while to find a solution and I've decided to post here what you need to modify in that code (in case somebody need it).
Instead of overriding dispatchTouchEvent
override onTouchEvent
. Use the same code of dispatchTouchEvent
and delete the method (you can read the difference between the two here http://developer.android.com/guide/topics/ui/ui-events.html#EventHandlers )
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean handled = mGesture.onTouchEvent(event);
return handled;
}
Then, add the following code which will decide to steal the event from the item children and give it to our onTouchEvent
, or let it be handled by them.
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
switch( ev.getActionMasked() ){
case MotionEvent.ACTION_DOWN:
mInitialX = ev.getX();
mInitialY = ev.getY();
return false;
case MotionEvent.ACTION_MOVE:
float deltaX = Math.abs(ev.getX() - mInitialX);
float deltaY = Math.abs(ev.getY() - mInitialY);
return ( deltaX > 5 || deltaY > 5 );
default:
return super.onInterceptTouchEvent(ev);
}
}
Finally, don't forget to declare the variables in your class:
private float mInitialX;
private float mInitialY;

- 11,460
- 4
- 56
- 71
-
13
-
ev.getActionMasked() in't available on android 2.1 platform. Do you know how to overcome this? – Eugene Popovich Nov 22 '12 at 06:34
-
seems that i can use int maskedAction = ev.getAction() & MotionEvent.ACTION_MASK which shold be equal to ev.getMaskedAction() – Eugene Popovich Nov 22 '12 at 06:47
-
Really usefull! but changing code into onTouchEvent I got a wierd offset. I kept it into dispatchTouchEvent and it works perfectly! Thanks – jbc25 Dec 08 '12 at 17:15
-
-
I have these jumps and code don't work if I use dispatchTouchEvent. must use onTouchEvent! What is the solution you are talking about please help. – hasan Jun 09 '13 at 05:33
-
Hi, any news on how to solve jumps? I think that the AdapterView itself tries to reposition the item at the beginning of the visible screen portion when it starts the scrolling. How to disable this? – ticofab Aug 14 '13 at 07:52
-
-
@Xavi Gil I have problem with horizontal list view. i am using paul library its working fine but when i am scrolling fast its getting stuck in right side and not even scrolling then. Please suggest me what should i do? – rupesh Mar 07 '14 at 08:06
-
I modified my code according to you but my setOnTouchListener call 10 times when I touch my text.I don't know why it's coming 10 times. – Faiz Anwar Mar 22 '14 at 12:15
Since Google introduced Android Support Library v7 21.0.0, you can use RecyclerView to scroll items horizontally. The RecyclerView widget is a more advanced and flexible version of ListView.
To use RecyclerView, just add dependency:
com.android.support:recyclerview-v7:23.0.1
Here is a sample:
public class MyActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_activity);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
recyclerView.setLayoutManager(layoutManager);
MyAdapter adapter = new MyAdapter(myDataset);
recyclerView.setAdapter(adapter);
}
}
More info about RecyclerView:

- 24,711
- 7
- 63
- 70
This is a little (very) late, but I'm posting this in case someone comes by this later.
The Support Library as of the Android L preview has a RecyclerView
that does exactly what you want.
Right now, you can only get it through the L preview SDK and you need to set your minSdk
to L
. But you can copy all of the necessary files into your project and use them that way until L is officially out.
You can download the preview docs here.
Warning: The API for Recycler View may change and it may have bugs.
Updated
The source code for horizontal listview is:
LinearLayoutManager layoutManager
= new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
RecyclerView myList = findViewById(R.id.my_recycler_view);
myList.setLayoutManager(layoutManager);

- 4,370
- 1
- 37
- 45

- 4,548
- 1
- 21
- 26
-
Hi, does it work ? because I try and I can't make a horizontal RecyclerView. Can you put some code ? thanks – Cocorico Jan 22 '15 at 15:07
-
Just set the `LinearLayoutManager` - see here: http://stackoverflow.com/questions/28460300/how-to-build-a-horizontal-listview-with-recyclerview – Stéphane Apr 08 '15 at 14:05
-
But binding Custom view to it there is lot of blank spaces, The width is not Wrap Content, There is lot of blank space after the CustomView Items. Is there any solution for this? – Jithin Angel'z Jas'z Sep 22 '21 at 18:11
Download the jar file from here
now put it into your libs folder, right click it and select 'Add as library'
now in main.xml put this code
<com.devsmart.android.ui.HorizontalListView
android:id="@+id/hlistview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
now in Activity class if you want Horizontal Listview with images then put this code
HorizontalListView hListView = (HorizontalListView) findViewById(R.id.hlistview);
hListView.setAdapter(new HAdapter(this));
private class HAdapter extends BaseAdapter {
LayoutInflater inflater;
public HAdapter(Context context) {
inflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return Const.template.length;
}
@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) {
HViewHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.listinflate, null);
holder = new HViewHolder();
convertView.setTag(holder);
} else {
holder = (HViewHolder) convertView.getTag();
}
holder.img = (ImageView) convertView.findViewById(R.id.image);
holder.img.setImageResource(Const.template[position]);
return convertView;
}
}
class HViewHolder {
ImageView img;
}

- 14,534
- 16
- 91
- 150
-
it's not supporting any selector, or any custom selector? any idea? – Nitin Misra Jan 17 '14 at 05:14
-
-
-
After putting it into libs folder, Right click it and hit 'Add as library' – M. Usman Khan May 20 '15 at 09:28
-
how to developer list of horizontallistview like in pulse,bbcnews please help me – Harsha Jul 03 '15 at 12:59
-
-
item with custom width other than **match_width**,it will only show one item. – zionpi Apr 12 '16 at 09:07
Its actually very simple: simply Rotate the list view to lay on its side
mlistView.setRotation(-90);
Then upon inflating the children, that should be inside the getView method. you rotate the children to stand up straight:
mylistViewchild.setRotation(90);
Edit: if your ListView doesnt fit properly after rotation, place the ListView inside this RotateLayout like this:
<com.github.rongi.rotate_layout.layout.RotateLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:angle="90"> <!-- Specify rotate angle here -->
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</com.github.rongi.rotate_layout.layout.RotateLayout>

- 22,222
- 4
- 42
- 56

- 3,103
- 2
- 25
- 25
-
2I've tried it - not so simple. I didn't manage to fit rotated view to screen width and height. And this API is available only in new devices. – Malachiasz Aug 01 '13 at 09:42
-
Before rotating, set the listViews width to the screen height And set the listviews height to the screens width.. (That is if you want the listview to fill the screen) else set the listview to the whatever height and width you want before rotating it. – kc ochibili Aug 07 '13 at 00:06
-
1
-
did you try changing the values after rotating? i don't see why it shouldn't work. (if you're wondering how you would know the previous height and width values after rotating, you could save them in a variable before rotating and then apply them after rotating. – kc ochibili Aug 07 '13 at 15:33
-
New version of this library ( http://stackoverflow.com/a/16589629/2075875 ) does the job as it should and works from android 2.3 while setRotation() is available since 3.0 so I don't want to play with rotate again, but I encourage you to try it yourself and present working code. – Malachiasz Aug 08 '13 at 07:25
-
Rotation itself may be simple, but the solution is far from straightforward. It's not working for me either. – Melllvar Nov 19 '13 at 15:31
-
I've used this and it works. You have to fiddle with your views - and widths and heights if you want full screen as kc ochibili says. But works. – Martin Sep 26 '14 at 04:16
-
My solution is to simply use ViewPager
widget. It isn't center-locked as Gallery
and has a built-in features for recycling views (as ListView
). You may see similar approach at Google Play app, whenever you deal with horizontally scrollable lists.
You just need to extend PagerAdapter
and perform a couple of tweaks there:
public class MyPagerAdapter extends PagerAdapter {
private Context mContext;
public MyPagerAdapter(Context context) {
this.mContext = context;
}
// As per docs, you may use views as key objects directly
// if they aren't too complex
@Override
public Object instantiateItem(ViewGroup container, int position) {
LayoutInflater inflater = LayoutInflater.from(mContext);
View view = inflater.inflate(R.layout.item, null);
container.addView(view);
return view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
@Override
public int getCount() {
return 10;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
// Important: page takes all available width by default,
// so let's override this method to fit 5 pages within single screen
@Override
public float getPageWidth(int position) {
return 0.2f;
}
}
As result, you'll have horizontally scrollable widget with adapter, like this:

- 3,524
- 2
- 32
- 38
-
3it's scrollable like ListView, but in horizontal direction. The only difference I see: items are scrolling one-by-one, so it's not possible to scroll somewhere to the middle of the next item. But that's how ViewPager works. – fraggjkee Apr 16 '14 at 08:27
Note: Android now supports horizontal list views using RecyclerView, so now this answer is deprecated, for information about RecyclerView : https://developer.android.com/reference/android/support/v7/widget/RecyclerView
I have developed a logic to do it without using any external horizontal scrollview library, here is the horizontal view that I achieved and I have posted my answer here:https://stackoverflow.com/a/33301582/5479863
My json response is this:
{"searchInfo":{"status":"1","message":"Success","clist":[{"id":"1de57434-795e-49ac-0ca3-5614dacecbd4","name":"Theater","image_url":"http://52.25.198.71/miisecretory/category_images/movie.png"},{"id":"62fe1c92-2192-2ebb-7e92-5614dacad69b","name":"CNG","image_url":"http://52.25.198.71/miisecretory/category_images/cng.png"},{"id":"8060094c-df4f-5290-7983-5614dad31677","name":"Wine-shop","image_url":"http://52.25.198.71/miisecretory/category_images/beer.png"},{"id":"888a90c4-a6b0-c2e2-6b3c-561788e973f6","name":"Chemist","image_url":"http://52.25.198.71/miisecretory/category_images/chemist.png"},{"id":"a39b4ec1-943f-b800-a671-561789a57871","name":"Food","image_url":"http://52.25.198.71/miisecretory/category_images/food.png"},{"id":"c644cc53-2fce-8cbe-0715-5614da9c765f","name":"College","image_url":"http://52.25.198.71/miisecretory/category_images/college.png"},{"id":"c71e8757-072b-1bf4-5b25-5614d980ef15","name":"Hospital","image_url":"http://52.25.198.71/miisecretory/category_images/hospital.png"},{"id":"db835491-d1d2-5467-a1a1-5614d9963c94","name":"Petrol-Pumps","image_url":"http://52.25.198.71/miisecretory/category_images/petrol.png"},{"id":"f13100ca-4052-c0f4-863a-5614d9631afb","name":"ATM","image_url":"http://52.25.198.71/miisecretory/category_images/atm.png"}]}}
Layout file :
<?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="match_parent"
android:orientation="vertical"
android:weightSum="5">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4" />
<HorizontalScrollView
android:id="@+id/horizontalScroll"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:id="@+id/ll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal">
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
class file:
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.ll);
for (int v = 0; v < collectionInfo.size(); v++) {
/*---------------Creating frame layout----------------------*/
FrameLayout frameLayout = new FrameLayout(ActivityMap.this);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, getPixelsToDP(90));
layoutParams.rightMargin = getPixelsToDP(10);
frameLayout.setLayoutParams(layoutParams);
/*--------------end of frame layout----------------------------*/
/*---------------Creating image view----------------------*/
final ImageView imgView = new ImageView(ActivityMap.this); //create imageview dynamically
LinearLayout.LayoutParams lpImage = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
imgView.setImageBitmap(collectionInfo.get(v).getCatImage());
imgView.setLayoutParams(lpImage);
// setting ID to retrieve at later time (same as its position)
imgView.setId(v);
imgView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// getting id which is same as its position
Log.i(TAG, "Clicked on " + collectionInfo.get(v.getId()).getCatName());
// getting selected category's data list
new GetSelectedCategoryData().execute(collectionInfo.get(v.getId()).getCatID());
}
});
/*--------------end of image view----------------------------*/
/*---------------Creating Text view----------------------*/
TextView textView = new TextView(ActivityMap.this);//create textview dynamically
textView.setText(collectionInfo.get(v).getCatName());
FrameLayout.LayoutParams lpText = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM | Gravity.CENTER);
// Note: LinearLayout.LayoutParams 's gravity was not working so I putted Framelayout as 3 paramater is gravity itself
textView.setTextColor(Color.parseColor("#43A047"));
textView.setLayoutParams(lpText);
/*--------------end of Text view----------------------------*/
//Adding views at appropriate places
frameLayout.addView(imgView);
frameLayout.addView(textView);
linearLayout.addView(frameLayout);
}
private int getPixelsToDP(int dp) {
float scale = getResources().getDisplayMetrics().density;
int pixels = (int) (dp * scale + 0.5f);
return pixels;
}
trick that is working here is the id that I have assigned to ImageView "imgView.setId(v)" and after that applying onClickListener to that I am again fetching the id of the view....I have also commented inside the code so that its easy to understand, I hope this may be very useful... Happy Coding... :)

- 442
- 5
- 12
-
1I have edited and posted the complete explanation here, thanks for suggestion :) – Abdul Aziz Oct 26 '15 at 09:04
-
Hello thanks for your code can you post the method `getPixelsToDP()`? – Skizo-ozᴉʞS ツ Nov 05 '15 at 19:30
-
@Skizo I have added that method at the end of java code, have a look – Abdul Aziz Nov 06 '15 at 05:42
This isn't much of an answer, but how about using a Horizontal Scroll View?

- 4,687
- 1
- 19
- 13
-
3It Works. But If i have large number of items then can not use the adapter kind of stuff and click events. – Praveen Jul 14 '10 at 09:01
-
try this http://indrapatel.blogspot.in/2013/10/horizontal-listview-in-android.html – Indra Oct 21 '13 at 08:28
You can use RecyclerView in the support library. RecyclerView is a generalized version of ListView that supports:
- A layout manager for positioning items
- Default animations for common item operations

- 1,640
- 1
- 22
- 30
-
This is the real answer as of this late date. But even this isn't ready yet and is still in 'preview' – Martin Sep 26 '14 at 04:04
I had to do the same for one of my projects and I ended up writing my own as well. I called it HorzListView is now part of my open source Aniqroid library.
http://aniqroid.sileria.com/doc/api/ (Look for downloads at the bottom or use google code project to see more download options: http://code.google.com/p/aniqroid/downloads/list)
The class documentation is here: http://aniqroid.sileria.com/doc/api/com/sileria/android/view/HorzListView.html

- 15,223
- 4
- 49
- 28
-
-
setSelection() method is there but may not be 100% implemented. Try it. – Sileria Mar 29 '13 at 12:03
I've done a lot of searching for a solution to this problem. The short answer is, there is no good solution, without overriding private methods and that sort of thing. The best thing I found was to implement it myself from scratch by extending AdapterView
. It's pretty miserable. See my SO question about horizontal ListViews.

- 1
- 1

- 18,367
- 15
- 63
- 70
-
Sadly your answer is the correct one. Even Google confirms that the only way for horizontal listview is Gallery. But Gallery is not the same as a horizontal listview. Would you be willing to share your code? Do you recycle views? – Patrick Boos Feb 22 '11 at 06:30
-
1Unfortunately the code was written for my company so therefore is proprietary. However, I do hope to find some free time in the coming months to rewrite it (the original implementation is pretty unstable) and release it to the public domain. I can also tell you that I started by taking [this demo](http://blogs.sonyericsson.com/developerworld/2010/06/23/android-tutorial-making-your-own-3d-list-part-3/) from Sony Ericsson, changing all 'x' to 'y' and all 'width' to 'height'. Then I removed the 3D transforms and added stopping-at-the-end behavior. – Neil Traft Feb 22 '11 at 18:15
-
@Neil Traft how did you fixed the items position? And what about stopping at the end? – Adrian Magdas Mar 02 '11 at 17:30
-
Honestly, it really was just a lot of guesswork. It took a long time to get it right, and I'm convinced that there's a better way. But the basic premise is, in the `fillListDown()` method, you need to keep track of the bottom edge of the last list item. But you don't know where that edge is until you actually create the last item (adapter.getCount()-1). So you wait until that item is created and then you can store the location of the edge. Once you know that, you can make sure that mListTop is never less than 0 and never more than the height of the list. – Neil Traft Mar 03 '11 at 03:35
-
1If you don't really, really, ABSOLUTELY need a horizontal list, I would STRONGLY encourage you to give up, or use the Gallery. – Neil Traft Mar 03 '11 at 03:36
-
I need to get rid off the center locking of Gallery, which is not easy to do, I would say impossible without rewriting the widget from scratch. So I will continue implementing a horizontal list view... – Adrian Magdas Mar 03 '11 at 06:33
For my application, I use a HorizontalScrollView containing LinearLayout inside, which has orientation set to horizontal. In order to add images inside, I create ImageViews inside the activity and add them to my LinearLayout. For example:
<HorizontalScrollView
android:id="@+id/photo_scroll"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="horizontal"
android:visibility="gone">
<LinearLayout
android:id="@+id/imageview_holder"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="match_parent">
</LinearLayout>
</HorizontalScrollView>
An this works perfectly fine for me. In the activity all I have to do is something like the code below:
LinearLayout imgViewHolder = findViewById(R.id.imageview_holder);
ImageView img1 = new ImageView(getApplicationContext());
//set bitmap
//set img1 layout params
imgViewHolder.add(img1);
ImageView img2 = new ImageView(getApplicationContext());
//set bitmap
//set img2 layout params
imgViewHolder.add(img2);
As I said that works for me, and I hope it helps somebody looking to achieve this as well.

- 547
- 1
- 11
- 21
HorizontialListView can't work when the data in the adapter is involved in another thread. Everything runs 100% on UI thread.This is a big problem in multithread. I think using HorizontialListView is not the best solution for your problem.HorzListView is a better way.You just replace your previous Gallery with HorzListView.You neednot modify the code about the adapter.Then everything goes the way you hope.See https://stackoverflow.com/a/12339708/1525777 about HorzListView.
I had used horizontal listview link in my project & I got good results. I had been used devsmart library initially but it gave me some issues. So best way to use horizontal listview link as it recovered my issues & also I recently launched my app on Google PlayStore using this library & got nice response from users. So I recommend you to use the same library which I mentioned above to show listview horizontally. Enjoy :)

- 559
- 6
- 14
well you can always create your textviews etc dynamically and set your onclicklisteners like you would do with an adapter

- 9,284
- 8
- 53
- 78
-
what do you mean? i cant get you? please post code snippet about your idea? – Praveen Jul 24 '10 at 10:05
-
please tell me the purpose of the "horizontal listview" will it have complex /multi views? eg 2 textboxes 1 progressbar? or just let's say plain text?Also do you have a fixed number of elements inside that view or you want to change it dynamically? Answer me these and i'll be able to help you with code – weakwire Jul 24 '10 at 12:16
-
i want to do the horizontal text gallery. but the selected item comes to the center as default. I want to be the selected item must be where i clicked that. please also check my posts: http://stackoverflow.com/questions/3237566/text-gallery-on-android and http://stackoverflow.com/questions/3318617/textview-on-horizontal-scrollview-in-android – Praveen Jul 24 '10 at 13:11
There is a great library for that, called TwoWayView, it's very easy to implement, just include the project library into your work space and add it as a library project to your original project, and then follow the following steps which are originally mentioned here:
First, let's add a style indicating the orientation of the ListView (horizontal or vertical) in (res/values/styles.xml):
<style name="TwoWayView">
<item name="android:orientation">horizontal</item>
</style>
Then,
In your Layout XML, use the following code to add the TwoWayView:
<org.lucasr.twowayview.TwoWayView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/lvItems"
style="@style/TwoWayView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"
tools:context=".MainActivity" />
and finally, just declare it and deal with it like any regular ListView
:
TwoWayView lvTest = (TwoWayView) findViewById(R.id.lvItems);
All the methods of ListView
will work here as usual, but there is only one difference I noticed, which is when setting the choice mode, the method setChoiceMode
not takes an int
value but a value from enum
called ChoiceMode
, so list_view.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
will be lvTest.setChoiceMode(ChoiceMode.SINGLE); // or MULTIPLE or NONE
.

- 8,914
- 14
- 83
- 118
You may use ViewFlipper to include the layout XML and add images , listview for each layout XML

- 2,971
- 15
- 70
- 141