【发布时间】:2015-08-18 08:30:18
【问题描述】:
我正在构建一个 Android 应用程序,我从本地数据库中获取数据并将其显示在自定义 ListView 中。
现在的问题是我想使用LinearLayout 代替ListView 作为滚动问题。
在我用于listView 的代码下方。
-
活动中的声明 -
lv = (ListView) findViewById(R.id.listView1); adapter = new CustomAdapter(this, dbh.fetchAllRec(), CursorAdapter.NO_SELECTION); lv.setAdapter(adapter); -
自定义列表视图 -
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" />
【问题讨论】:
-
解释你的问题。我认为您不应该摆脱列表视图。
-
@ThomasR。实际上,我在 listview 上方使用了很多工具,当我滚动 dowen listView 时,我需要根据我的页面。整页应该滚动而不是 listView
-
可以显示你的xml文件
-
线性布局为什么需要adater来设置数据...
-
不要放弃你的列表视图来支持线性布局 - 这样做会非常具有挑战性。
标签: android android-layout android-listview android-linearlayout