如何在Android中将我的ListView更改为LinearLayout?

时间:2015-08-18 08:30:19

标签: android android-layout android-listview android-linearlayout

我正在构建一个Android应用程序,我从本地数据库中提取数据并将其显示在自定义ListView中。

现在的问题是我想用LinearLayout代替ListView作为滚动问题。

我在listView使用的代码下面。

  1. 活动宣言 -

    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" />
    

1 个答案:

答案 0 :(得分:0)

请描述所有问题范围。

正如我从问题和评论中看到的那样,你有一个ListView,它在屏幕的某些部分滚动,但你需要滚动所有的屏幕。并且您希望将ListView强制转换为LinearLayout。那是对的吗?如果是的话,这不是一个好主意,特别是如果你的ListView包含很多项目。最好将标头添加到ListView或使用自定义NonScrollableListView类。但对我来说,第一选择是可取的。

等待你的评论,回复后对我来说会更清楚。