我有一個列表視圖顯示給用戶,我想辦法使列表視圖非無限,並將其限制爲25個項目。我也試圖限制用戶能夠在EditText中顯示一個數字。我試圖在列表視圖中添加android:inputType =「text | textNoSuggestions」,但這已被證明是無效的。限制列表視圖,並只顯示字母
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/white_wallpaper"
>
<ListView
android:id="@+id/listMessages"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/divider"
android:divider="@null"
android:dividerHeight="0dp"
android:inputType="text|textNoSuggestions"
android:padding="0dip"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
tools:listitem="@layout/message_left" />
<RelativeLayout
android:id="@+id/divider"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="@color/off_white"
android:layout_above="@+id/relSendMessage" />
<RelativeLayout
android:id="@+id/relSendMessage"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:background="#ddd"
android:paddingLeft="10dp"
android:layout_alignParentBottom="true">
<EditText
android:id="@+id/messageBodyField"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignBottom="@+id/sendButton"
android:layout_alignTop="@+id/sendButton"
android:layout_marginBottom="-4dp"
android:layout_marginRight="10dp"
android:inputType="text|textNoSuggestions"
android:layout_toLeftOf="@+id/sendButton"
android:background="@android:color/white"
android:hint="@string/message_elipses"
android:textColor="#000000"
android:textColorLink="#adefda"
android:textSize="14sp" />
<Button
android:id="@+id/sendButton"
android:layout_width="72dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_margin="4dp"
android:background="@drawable/button_send" />
</RelativeLayout>
<Button
android:id="@+id/iSchedule"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:alpha="0.7"
android:background="#C11B17"
android:text="Schedule"
android:textColor="#f2f2f2"
android:textSize="20sp"
android:textStyle="bold"
android:typeface="serif" />
</RelativeLayout>
任何建議將不勝感激。
更新:
至於限制ListView的項目,我有下面的代碼: 下面是列表視圖是如何編程顯示:
messagesList = (ListView) findViewById(R.id.listMessages);
messageAdapter = new MessageAdapter(this);
將以下工作:
@Override
public int getCount() {
messagesList.setAdapter(messageAdapter);
return 25;
}
通過「試圖限制用戶無法在EditText中顯示數字」,您的意思是您不希望用戶能夠在該字段中輸入數字嗎?如果你能清楚這一點,這將有所幫助。 – apoorvk 2014-10-10 22:22:31
啊,是的,這就是我的意思。我不希望用戶能夠在 – John 2014-10-10 22:36:39