我有一个编辑文本,输入类型为数字。但是在完成任务之后,如果我再次单击编辑文本,则输入类型将更改为文本。
大约一秒钟,它会将输入类型显示为数字,很快就会自动将编辑文本的输入类型更改为文本。即使我点击按键,编辑文本也不会显示任何内容。
我检查了logcat,我得到了这个:
12-20 00:03:09.747: I/Choreographer(5638): Skipped 308 frames! The application may be doing too much work on its main thread.
12-19 23:57:39.917: W/IInputConnectionWrapper(5638): getTextBeforeCursor on inactive InputConnection
12-20 00:02:45.917: I/InputAttributes(412): InputType.TYPE_NULL is specified
我查看此链接:getExtractedText on inactive InputConnection warning on android
但无法找到解决方案。如果有人可以帮我解决这个问题,将会很有帮助。
这是我的自定义单元格xml(此编辑文本位于列表视图中):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:background="@color/app_main_color"
android:orientation="vertical"
android:padding="5dp" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<EditText
android:id="@+id/etPolicyNum"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="10dp"
android:background="@drawable/custom_edittext"
android:ems="10"
android:hint="@string/policy_number"
android:inputType="number"
android:nextFocusDown="@+id/etOwner1LastName"
android:padding="10dp" />
<EditText
android:id="@+id/etNaic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/etExpiryDate"
android:layout_below="@id/etPolicyNum"
android:layout_marginBottom="5dp"
android:background="@drawable/custom_edittext"
android:ems="10"
android:hint="@string/naic_code"
android:inputType="number"
android:padding="10dp" />
<EditText
android:id="@+id/etExpiryDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/etPolicyNum"
android:layout_below="@id/etNaic"
android:background="@drawable/custom_edittext"
android:clickable="true"
android:ems="10"
android:focusable="false"
android:hint="@string/expiration_date"
android:inputType="date"
android:padding="10dp" />
<ImageView
android:id="@+id/imgCameraImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/etExpiryDate"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/etNaic"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@id/etExpiryDate"
android:clickable="true"
android:contentDescription="@string/camera_image_desc"
android:src="@drawable/camera_button"
android:visibility="invisible" />
<ImageView
android:id="@+id/imgOwner1List"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/etPolicyNum"
android:layout_alignParentRight="true"
android:clickable="true"
android:contentDescription="@string/list_image_desc"
android:src="@drawable/list_button"
android:visibility="invisible" />
</RelativeLayout>
</LinearLayout>
这是我的自定义适配器:
public class CustomAdapter_Insurance extends ArrayAdapter<RowData_Insurance>
{
//Variable declarations
private LayoutInflater mInflater;
private int mResource;
private static Typeface sTfFont;
private CustomAdapterCallBack callback;
public static String PolicyNum[],Naic[];
private CommonFunctions mcfObj;
public CustomAdapter_Insurance(Context context, int resource,int textViewResourceId, List<RowData_Insurance> objects,LayoutInflater mInflater,CustomAdapterCallBack callback)
{
super(context, resource, textViewResourceId, objects);
this.mInflater=mInflater;
mResource=resource;
PolicyNum=new String[objects.size()];
Naic=new String[objects.size()];
if(sTfFont==null)
{
sTfFont = Typeface.createFromAsset(context.getAssets(),"fonts/HelveticaNeue-Light.ttf");
}
if(mcfObj==null)
{
mcfObj=new CommonFunctions(context);
}
this.callback=callback;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
ViewHolder holder = null;
TextView mName = null;
TextView mAddress = null;
EditText mPolicyNum = null;
EditText mNaic = null;
EditText mExpiryDate = null;
ImageView mImgCameraImage=null;
if(null == convertView)
{
convertView = mInflater.inflate(mResource, null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
}
holder = (ViewHolder) convertView.getTag();
mName=holder.getName();
mAddress=holder.getAddress();
mPolicyNum=holder.getPolicyNum();
mNaic=holder.getNaic();
mExpiryDate=holder.getExpiryDate();
mImgCameraImage=holder.getImgCameraImage();
RowData_Insurance rowData= getItem(position);
if(rowData.mImgFlag)
{
mImgCameraImage.setVisibility(View.VISIBLE);
if(rowData.mBmImage!=null)
{
mImgCameraImage.setImageBitmap(rowData.mBmImage);
}
else
{
mImgCameraImage.setImageResource(R.drawable.camera_button);
}
}
else
{
mImgCameraImage.setVisibility(View.INVISIBLE);
}
mName.setTypeface(sTfFont);
mAddress.setTypeface(sTfFont);
mPolicyNum.setTypeface(sTfFont);
mNaic.setTypeface(sTfFont);
mExpiryDate.setTypeface(sTfFont);
mName.setText(rowData.mName);
mAddress.setText(rowData.mAddress);
if(PolicyNum[rowData.mId]==null)
{
mPolicyNum.setText(rowData.mPolicyNum);
}
else
{
mPolicyNum.setText(PolicyNum[rowData.mId]);
}
mNaic.setText(rowData.mNaic);
mExpiryDate.setText(rowData.mExpiryDate);
//Setting listeners
mPolicyNum.addTextChangedListener(new CustomTextWatcher(mPolicyNum,rowData,1));
mNaic.addTextChangedListener(new CustomTextWatcher(mNaic,rowData,2));
mImgCameraImage.setOnClickListener(new CustomClickListener(position,1,mPolicyNum,mNaic));
mExpiryDate.setOnClickListener(new CustomClickListener(position,2,mPolicyNum,mNaic));
return convertView;
}
private class ViewHolder
{
private View mRow;
private TextView mName = null;
private TextView mAddress = null;
private EditText mPolicyNum = null;
private EditText mNaic = null;
private EditText mExpiryDate = null;
private ImageView mImgCameraImage=null;
public ViewHolder(View row)
{
mRow = row;
}
public TextView getName()
{
if(null == mName)
{
mName = (TextView) mRow.findViewById(R.id.txtName);
}
return mName;
}
public TextView getAddress()
{
if(null == mAddress)
{
mAddress = (TextView) mRow.findViewById(R.id.txtAddress);
}
return mAddress;
}
public EditText getPolicyNum()
{
if(null == mPolicyNum)
{
mPolicyNum = (EditText) mRow.findViewById(R.id.etPolicyNum);
}
return mPolicyNum;
}
public EditText getNaic()
{
if(null == mNaic)
{
mNaic = (EditText) mRow.findViewById(R.id.etNaic);
}
return mNaic;
}
public EditText getExpiryDate()
{
if(null == mExpiryDate)
{
mExpiryDate = (EditText) mRow.findViewById(R.id.etExpiryDate);
}
/*mExpiryDate.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
if(callback != null)
{
callback.CallDateWheel(sSelectedPosition);
}
}
});*/
return mExpiryDate;
}
public ImageView getImgCameraImage()
{
if(null == mImgCameraImage)
{
mImgCameraImage = (ImageView) mRow.findViewById(R.id.imgCameraImage);
}
/*mImgCameraImage.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
if(callback != null)
{
callback.CallPhotoDialog(sSelectedPosition);
}
}
});*/
return mImgCameraImage;
}
}
public interface CustomAdapterCallBack
{
public void CallDateWheel(int id);
public void CallPhotoDialog(int id);
}
private class CustomTextWatcher implements TextWatcher {
private EditText EditText;
private RowData_Insurance item;
private int choice;
public CustomTextWatcher(EditText e, RowData_Insurance item,int choice)
{
this.EditText = e;
this.item = item;
this.choice=choice;
}
@Override
public void afterTextChanged(Editable arg0)
{
if(choice==1)
{
PolicyNum[item.mId]=EditText.getText().toString();
}
else if(choice==2)
{
Naic[item.mId]=EditText.getText().toString();
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
}
private class CustomClickListener implements OnClickListener
{
int position;
int choice;
EditText etPolicyNum;
EditText etNaic;
public CustomClickListener(int position,int choice,EditText etPolicyNum, EditText etNaic)
{
this.position=position;
this.choice=choice;
this.etPolicyNum=etPolicyNum;
this.etNaic=etNaic;
}
@Override
public void onClick(View v)
{
if(choice==1)
{
callback.CallPhotoDialog(position);
}
else if(choice==2)
{
callback.CallDateWheel(position);
}
}
}
}
单击mExpiryDate后出现问题。在mExpiryDate的click事件中,使一个处于可见状态的布局变为可见状态。
答案 0 :(得分:3)
尝试在xml中使用它。它可能会帮助您,通过禁用数字以外的按钮以及是否要添加更多按钮。
android:digits="0123456789"
答案 1 :(得分:3)
我认为你的列表视图状态不是滚动管理的。
mName.setTypeface(sTfFont);
mAddress.setTypeface(sTfFont);
mPolicyNum.setTypeface(sTfFont);
mNaic.setTypeface(sTfFont);
mExpiryDate.setTypeface(sTfFont);
您是否通过将其放入if(null==convertView)
块进行检查,您应该通过仅在该块内初始化这些相同的字段来进行检查。
mName=holder.getName();
mAddress=holder.getAddress();
mPolicyNum=holder.getPolicyNum();
mNaic=holder.getNaic();
mExpiryDate=holder.getExpiryDate();
mImgCameraImage=holder.getImgCameraImage();
**注意:改变解决方案:我在动态列表视图中遇到了类似的问题,但是我在每个列表项中都有一个微调器,我做的是,我删除了持有者逻辑并将字段与ArrayList值紧密绑定,虽然它对我有用滚动速度稍慢。
答案 2 :(得分:2)
从跳过308帧!应用程序可能在其主线程上做了太多工作。
您的错误表明您在应用程序的主UI线程上执行了一些耗时的任务,这需要很长时间并且会阻止UI。
尝试使用以下策略以提高应用效果:
另请查看Thread
答案 3 :(得分:2)
这解决了这个问题:
android:descendantFocusability="afterDescendants"
我将上面的代码添加到xml中的listview中,它解决了这个问题。