roy mathew
roy mathew

Reputation: 7800

Issues related to edit text input type

I am having an edit text which is having input type as number. But after doing a task, if again I click on the edit text the input type is changing to text.

For about a second it will display the input type as number and soon it is automatically changing the edit text's input type to text. Even if I click on the keys nothing gets displayed on the edit text.

I checked logcat and I am getting this:

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

I check this link: getExtractedText on inactive InputConnection warning on android

But unable to find a solution. It will be helpful if someone can help me to solve this issue.

This is my custom cell xml(This edit text is in a listview):

<?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>

Here is my custom adapter:

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);
            }
        }

    }
}

Issue occurs after clicking the mExpiryDate. On click event of mExpiryDate makes a layout which is in gone visibility state to visible state.

Upvotes: 4

Views: 2369

Answers (4)

roy mathew
roy mathew

Reputation: 7800

This solved the issue:

android:descendantFocusability="afterDescendants"

I added the above code to listview in xml and it solved the issue.

Upvotes: 2

GrIsHu
GrIsHu

Reputation: 23638

From the line Skipped 308 frames! The application may be doing too much work on its main thread.

Your error shows that you are doing some time consuming tasks on your Main UI thread of your application which requires much time and it blocks the UI.

Try to use the following strategies in order to improve your app performance:

  • Use multi-threading programming if possible. The performance benefits are huge, even if your smart phone has one core (threads can run in different cores, if the processor has two or more). It's useful to make your app logic separated from the UI. Use Java threads, AsyncTask or IntentService. Check this.
  • Read and follow the misc performance tips of Android development website. Check here.

Also check out Thread

Upvotes: 2

mayank_droid
mayank_droid

Reputation: 1015

I think your state of listview is not managed on scroll.

    mName.setTypeface(sTfFont);
    mAddress.setTypeface(sTfFont);
    mPolicyNum.setTypeface(sTfFont);
    mNaic.setTypeface(sTfFont);
    mExpiryDate.setTypeface(sTfFont);

did you check by putting it into that if(null==convertView) block, you should check by initializing these same fields inside that block only.

    mName=holder.getName();
    mAddress=holder.getAddress();
    mPolicyNum=holder.getPolicyNum();
    mNaic=holder.getNaic();
    mExpiryDate=holder.getExpiryDate();
    mImgCameraImage=holder.getImgCameraImage();

**Note: Alter Solution : I faced similar issue in dynamic listview but I had a spinner in each list item and what I did is, I removed holder logic and tightly bound ArrayList values with fields and it worked for me though it made scrolling little slower.

Upvotes: 3

akshay
akshay

Reputation: 5979

try using this in your xml. It might help you, by disabling buttons other than digits and if you want to add some more buttons.

android:digits="0123456789"

Upvotes: 3

Related Questions