我实现了一个包含多个edittexts的listview。列表中的每一行都有这样的编辑文本:
<EditText
android:id="@+id/valueEt"
android:singleLine="true"
android:inputType="numberDecimal|numberSigned"
android:maxLength="6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:textColor="@color/white"
android:layout_toStartOf="@id/infoView"
android:layout_toLeftOf="@id/infoView"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"/>
因此,当您单击其中一个edittexts时,您将能够输入数字和点数。
但如果你单击一个它显示正确的键盘(数字+点)然后编辑文本失去焦点,键盘切换到普通键盘。如果你点击一个键没有任何反应。
我的适配器:
public class CustomBodyAdapter extends ArrayAdapter {
private final String[] tags;
private final float[] values;
private Date date;
public CustomBodyAdapter(Context context, String[] tags, Date date, float[] values) {
super(context, R.layout.custom_row_image_text, tags);
this.tags = tags;
this.date = date;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(getContext());
View customView = inflater.inflate(R.layout.custom_row_body, parent, false);
TextView tagTv = (TextView) customView.findViewById(R.id.tagTv);
EditText valueEt = (EditText) customView.findViewById(R.id.valueEt);
ImageView infoView = (ImageView) customView.findViewById(R.id.infoView);
tagTv.setText(tags[position]);
if(position == 0){
valueEt.setText(date.toString());
valueEt.setEnabled(false);
infoView.setVisibility(View.INVISIBLE);
}else if(position == 3 || position == 4 || position == 5){
valueEt.setText(values[position] + "");
}else{
valueEt.setText(values[position] + "");
infoView.setVisibility(View.INVISIBLE);
}
return customView;
}
}
这就是我添加listview的方式:
Date today = currentCalender.getTime();
float[] values = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
cba = new CustomBodyAdapter(BodyActivity.this, getResources().getStringArray(R.array.bodyItems), today, values);
listView.setAdapter(cba);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
});