我有一个向用户显示的列表视图,我正在找出使listview非无限的方法,并将其限制为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;
}
答案 0 :(得分:1)
因此,要处理编辑文本问题,可以使用此
<EditText
...
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
/>
现在上面的字符是唯一可以输入EditText的字符。您也可以在android:inputType
中更改键盘类型。
此外,您希望限制ListView中的条目数。在代码的BaseAdapter方法中,更改此:
@Override
public int getCount() {
return 25;
}
更新:
您可以做的是创建自定义ArrayAdapter并在那里修改getCount方法。由于getCount()
完全属于不同的类,您只想更改那里的最大 25 ,然后将列表视图设置为该适配器。您可能需要查看here以获得ArrayAdapters的更多用途。