-1

I have a listview in which i am adding elements from an array,i need to show only three rows in the screen and making rest all to be scrollable,that is it can be viewed only when we scroll,how to acheive this?

I have custom adapter.Below is my listview

 <LinearLayout  android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <ListView android:id="@+id/listView"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:divider="#00000000"
            android:dividerHeight="5dp"
           />

and adapter has

 @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        Holder holder=new Holder();
        View rowView;
        rowView = inflater.inflate(R.layout.tabitem, null);
        holder.tv=(TextView) rowView.findViewById(R.id.textView1);
        holder.tv1=(TextView)rowView.findViewById(R.id.textView2);
        holder.tv2=(TextView) rowView.findViewById(R.id.textView3);
        holder.tv3=(TextView) rowView.findViewById(R.id.textView4);
        holder.tv4=(TextView) rowView.findViewById(R.id.textView5);
        holder.tv.setText(result[position]);
        holder.tv1.setText(result1[position]);
        holder.tv2.setText(result2[position]);
        holder.tv3.setText(result3[position]);
        holder.tv4.setText(result4[position]);
        rowView.setBackgroundColor(Color.parseColor("#F1F1FF"));

        rowView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Toast.makeText(context, "You Clicked "+result[position], Toast.LENGTH_LONG).show();
            }
        });
        return rowView;
    }

}
pihu
  • 93
  • 1
  • 11
  • 3 fixed rows and the rest scrollable? put the 3 rows **outside** the ListView and the rest **inside**. – Phantômaxx Jan 22 '15 at 13:50
  • not this way,i meant only three should be visible when the user opens the screen and rest can be visible only when he scrolls – pihu Jan 23 '15 at 08:57
  • So, you want 3 rows to be as high as the whole screen (each row being 1/3rd of the total height tall)... – Phantômaxx Jan 23 '15 at 09:02
  • I have a screen having textview then listview and finally comment and buttons,i am facing a issue buttons being moved inside the screen out of visibility ,so i wanted to fix the height of listview so that only few rows are visible and to view other rows a user has to scroll – pihu Jan 23 '15 at 09:13
  • Well, this is the normal `ListView` behaviour... – Phantômaxx Jan 23 '15 at 09:15
  • has and when rows get added its size increases thats fine,but i need to see all the rows only on scroll.My other layouts are getting off the visiblitiy – pihu Jan 23 '15 at 09:23
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/69433/discussion-between-pihu-and-der-golem). – pihu Jan 23 '15 at 09:27
  • 1
    Simply **fix the ListView height**, either by using a fixed value in dp or by using **weights** – Phantômaxx Jan 23 '15 at 09:43

1 Answers1

1

I believe this can be done with the help of relative layout. This answer is similar to what you are trying to achieve Basically you have relative layout as parent and play with alignParentTop, alignParentBottom, android:layout_above, android:layout_below attributes in view tags.

Community
  • 1
  • 1
Dhir Pratap
  • 1,188
  • 11
  • 14