Search This Blog

Monday 16 April 2012

Creating HorizontalScrollView in Android

Today i am going to describing a powerful tool of android, Horizontal Listview with complete source in the end.
Horizontal ListView sometimes is very useful and it save our day. HorizontalScrollView is nothing but a widget, If you add more element than its visible area then it start scrolling horizontally. Bit main disadvantage is that you can not perform click on the base of position quite easily

If you need some explanation then read complete step else download code with link in the end and play with it

Step 1) Create one new Project name HorizontalListviewDemo

Step 2) Change your main activity to as follow class

 package com.ahmad;  
 import android.os.Bundle;  
 import android.view.View;  
 import android.view.View.OnClickListener;  
 import android.widget.Button;  
 import android.widget.LinearLayout;  
 import android.widget.Toast;  
 public class SecondActivity extends Activity implements OnClickListener {  
  Button btn1, btn2, btn3, btn4;  
  public LinearLayout middle;  
  public void onCreate(Bundle savedInstanceState) {  
  btn1 = (Button) findViewById(;  
  btn2 = (Button) findViewById(;  
  btn3 = (Button) findViewById(;  
  try {  
   btn4 = (Button) findViewById(;  
  } catch (Exception e) {  
  public void onClick(View v) {  
  if (v.getId() == {  
   Toast.makeText(this, "Second Act Btn1 Clicked", Toast.LENGTH_LONG)  
  } else if (v.getId() == {  
   Toast.makeText(this, "Second Act Btn 2 Clicked", Toast.LENGTH_LONG)  
  } else if (v.getId() == {  
   Toast.makeText(this, "Second Act Btn 3 Clicked", Toast.LENGTH_LONG)  
  } else if (v.getId() == {  
   Toast.makeText(this, "Second Act Btn 4 Clicked", Toast.LENGTH_LONG)  
Step 3)Make one Layout and add HorizontalListview and some content inside

Now enjoy after running it.complete source link is below.See more article on ListView in blog tag Android ListView
                                                          Download Complete Project

Article You may Like

Android Listactivity with header


  1. umm....I don't think this is a horizontalListview. This is just a horizontal scroll view with some item inside. It is different from what listview does. (at least listview can reuse view when you scroll)

    1. Yes , i do agree. Horizontal ListView does not do what ListView do. ListView recycle view with Adapter.


Feedback always help in improvement. If you have any query suggestion feel free to comment and Keep visiting my blog to encourage me to blogging

Android News and source code