Scrolling list vertically

I am trying to implement a list view with a horizontal scroll view. I get a logcat "null pointer exception" error when setting up a list view adapter. My list view should appear inside a sherlock fragment

public class Trending extends SherlockFragment { List<String> list; ListView prog_list; // Array of integers points to images stored in /res/drawable-ldpi/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View myFragmentView = inflater.inflate(R.layout.trendslay, container,false); prog_list = (ListView)myFragmentView.findViewById(R.id.lv1); return prog_list; } /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); list = new ArrayList<String>(); list.add("hi"); list.add("hello"); list.add("how ru"); list.add("hi"); list.add("hello"); list.add("how ru"); list.add("hi"); list.add("hello"); list.add("how ru"); ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, android.R.id.text1,list); prog_list.setAdapter(adapter); } 
+1
android
Jan 24
source share
4 answers

I had the same requirement to create a horizontal ListView inside a Vertical ListView, and I tried to control this using TwoWayView to horizontally scroll vertically scrollable ListView items. You can check my demo for the same on github as VerticalHorizontalListView.

+7
Aug 6 '13 at 9:00
source share
— -

You can use the vertical scroll view.

and in your android:fillViewport="true" layout android:fillViewport="true" this will give you a horizontal scroll effect without using a horizontal scroll view

 <ScrollView android:id="@+id/scrollView1" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" > <ListView android:id="@+id/listView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" > </ListView> </LinearLayout> </ScrollView> 
+1
Jan 24 '13 at 6:11
source share

Add prog_list.setHorizontalScrollBarEnabled(true); after setAdapter();

0
Jan 24 '13 at 5:59
source share

TRY IT:

 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View myFragmentView = inflater.inflate(R.layout.trendslay,container,false); prog_list = (ListView)myFragmentView.findViewById(R.id.lv1); list = new ArrayList<String>(); list.add("hi"); list.add("hello"); list.add("how ru"); list.add("hi"); list.add("hello"); list.add("how ru"); list.add("hi"); list.add("hello"); list.add("how ru"); ArrayAdapter<String> adapter = new ArrayAdapter<String>getActivity(), android.R.layout.simple_list_item_1, android.R.id.text1,list); prog_list.setAdapter(adapter); return myFragmentView ; } 
0
Jul 18 '16 at 11:47
source share



All Articles