0

I am building an Android application where I am fetching data from a local DB and displaying it in a custom ListView.

Now the problem is I want to use LinearLayout in place of ListView as a scroll problem.

Below my code that I am using for listView.

  1. Declaration in activity -

    lv = (ListView) findViewById(R.id.listView1);
    
    adapter = new CustomAdapter(this, dbh.fetchAllRec(),
            CursorAdapter.NO_SELECTION);
    lv.setAdapter(adapter);
    
  2. CustomListView -

    public class CustomAdapter extends CursorAdapter {
    
    ///---  cunstructor ---///
    
    @Override
    public void bindView(View v, Context context, Cursor c) {
    // TODO Auto-generated method stub
    //TextView tvId=(TextView)v.findViewById(R.id.tvId);
    
    //tvId.setText(c.getString(c.getColumnIndex(c.getColumnName(0))));
    //tvId.setText(c.getString(arg0));
    
    TextView tvEmail = (TextView)v.findViewById(R.id.tvEmail);
    tvEmail.setText(c.getString(c.getColumnIndex(c.getColumnName(4))));
    
    TextView tvPword = (TextView)v.findViewById(R.id.tvPword);
    tvPword.setText(c.getString(c.getColumnIndex(c.getColumnName(5))));
    
    TextView tvMobile =(TextView)v.findViewById(R.id.tvMobile);
    String FlatNumber = c.getString(c.getColumnIndex(c.getColumnName(1)));
    String Landmark = c.getString(c.getColumnIndex(c.getColumnName(2)));
    String Address = c.getString(c.getColumnIndex(c.getColumnName(3)));
    tvMobile.setText(FlatNumber+","+Landmark+","+Address);
    
      }
    
    @Override
      public View newView(Context context, Cursor c, ViewGroup parent ) {
        // TODO Auto-generated method stub
      LayoutInflater inflater = LayoutInflater.from(parent.getContext());
      View v = inflater.inflate(R.layout.cust_list, parent, false);
    
      return v;
     }
    
    }
    

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/locationT1"
        android:textSize="14sp" />
    
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:text="@string/locationT2"
        android:textSize="10sp" />
    
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_marginTop="@dimen/margin_10"
        android:background="@drawable/cornerround">
    
        <ImageView
            android:id="@+id/mapLogo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:contentDescription="@null"
            android:src="@drawable/locationicon" />
    
        <TextView
            android:id="@+id/pickerUserAddress"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginRight="@dimen/margin_50"
            android:layout_toRightOf="@+id/mapLogo"
            android:lines="1"
            android:textSize="@dimen/text_size_14" />
    
        <ImageView
            android:id="@+id/editLocation"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:contentDescription="@null"
            android:src="@drawable/editiconn" />
    </RelativeLayout>
    
    <EditText
        android:id="@+id/pickerUserName"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginTop="@dimen/margin_10"
        android:background="@drawable/cornerround"
        android:hint="@string/hintEnterName"
        android:textSize="@dimen/text_size_14" />
    
    <EditText
        android:id="@+id/pickerUserPhoneNumber"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginTop="@dimen/margin_10"
        android:background="@drawable/cornerround"
        android:hint="@string/hintEnterPhoneNumber"
        android:inputType="phone"
        android:maxLength="12"
        android:textSize="@dimen/text_size_14" />
    
    <EditText
        android:id="@+id/pickerUserFlaNumber"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginTop="@dimen/margin_10"
        android:background="@drawable/cornerround"
        android:hint="@string/hintFlatNumber"
        android:textSize="@dimen/text_size_14" />
    
    <EditText
        android:id="@+id/pickerLandMark"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginTop="@dimen/margin_10"
        android:background="@drawable/cornerround"
        android:hint="@string/hintLandmark"
        android:textSize="@dimen/text_size_14" />
    
    <RelativeLayout
        android:id="@+id/pickerCollectCash"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/margin_10">
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_centerVertical="true"
            android:text="@string/cashToCollect" />
    
        <EditText
            android:id="@+id/pickerCashToCollect"
            android:layout_width="@dimen/width_100"
            android:layout_height="40dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_gravity="end"
            android:layout_marginTop="@dimen/margin_5"
            android:background="@drawable/cornerround"
            android:hint="@string/hintRs"
            android:inputType="phone"
            android:maxLength="5"
            android:textSize="@dimen/text_size_14" />
    
    </RelativeLayout>
    
    
    <RelativeLayout
        android:id="@+id/PickerDoneBtn"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_gravity="right"
        android:layout_marginTop="10dp"
        android:background="@color/secondary_color">
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:text="PROCEED" />
    
    </RelativeLayout>
    
    
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:background="@color/newDesignGrey">
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="5dp"
            android:text="Saved Addresses"
            android:textSize="@dimen/text_size_14"
            android:textStyle="bold" />
    </RelativeLayout>
    
    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:dividerHeight="0dp"
        android:scrollbars="none"
        android:background="@color/newDesignGrey" />
    

sofquestion 9
  • 147
  • 3
  • 11

1 Answers1

0

Please, describe all scope of issue.

As I see from question and comments, you've got a ListView, which scrolls on some part of the screen, but you need to scroll all the screen. And you want to cast ListView to LinearLayout. Is that correct? If yes, it's not good idea, specially if your ListView contains a lot of items. It's better to add header to your ListView or use custom NonScrollableListView class. But as for me first option is preferable.

Waiting comments from you, it'll be a bit more clear for me after your response.

Anton
  • 419
  • 2
  • 7
  • 19
  • Yes You are right. change all the tool to the header will take a lot of time can you suggested something else – sofquestion 9 Aug 18 '15 at 09:12
  • then you can also add the listview and whole other views in a scrollview. – Ansal Ali Aug 18 '15 at 09:16
  • It's not good practice to add ListView inside ScrollView. Basically, in that case you will have two scroll handlers on the screen and android won't know which to use. When I tried to perform such trick, I just received first item of my ListView, that's all. Actually, I don't see a problem in putting your views in some container, getting id of this container and making a header from it, but if such a problem might be, this topic may help you: http://stackoverflow.com/questions/4338185/how-to-get-a-non-scrollable-listview See comments, there are a lot of solutions. – Anton Aug 18 '15 at 09:22
  • I dont think so and this could support my views..http://stackoverflow.com/questions/18813296/non-scrollable-listview-inside-scrollview – Ansal Ali Aug 18 '15 at 09:36
  • check 2nd answer of this link too http://stackoverflow.com/questions/6210895/listview-inside-scrollview-is-not-scrolling-on-android – Ansal Ali Aug 18 '15 at 09:39