Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
521 views
in Technique[技术] by (71.8m points)

android - Cannot Type EditText in ExpandableListView Child

i am using expandableList and each child has its edittext to enter a number... when the child is pressed, the edittext shows. if it is not, the edittext stays invisible.. but when i tap on the edittext, the keyboard shows in number (because i set type input : number) only 1 second. after that it turns to common keyboard. even it backs to common keyboard, still, i cant type on the edittext... here is my code

 public View getChildView(int groupPosition, int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        final String childText = (String) getChild(groupPosition, childPosition);
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) this.context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(
                    R.layout.konsumsi_user_expand_listchild, null);
        }
        final TextView listChild = (TextView) convertView
                .findViewById(R.id.lblListItemKonsumsi);
        listChild.setText(childText);
        final EditText kolomTakaran = (EditText) convertView
                .findViewById(R.id.kolomTakaran);
        listChild.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                kolomTakaran.setVisibility(View.VISIBLE);

                if (childText == "kol") {
                    takaran = 50;
                } else {
                    takaran = 0;
                }
                kolomTakaran.addTextChangedListener(new TextWatcher() {

                    @Override
                    public void onTextChanged(CharSequence s, int start,
                            int before, int count) {
                        // TODO Auto-generated method stub
                        Toast.makeText(context, "a", Toast.LENGTH_LONG).show();
                    }

                    @Override
                    public void beforeTextChanged(CharSequence s, int start,
                            int count, int after) {
                        Toast.makeText(context, "b", Toast.LENGTH_LONG).show();
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void afterTextChanged(Editable s) {
                        // TODO Auto-generated method stub
                        Toast.makeText(context, "c", Toast.LENGTH_LONG).show();
                        takaran = Integer.parseInt(s.toString());
                    }
                });
            }
        });

        return convertView;
    }

and here is my child xml

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="55dp" >

    <TextView
        android:id="@+id/lblListItemKonsumsi"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:paddingBottom="5dp"
        android:paddingLeft="25dp"
        android:paddingTop="5dp"
        android:textSize="14dp" />

    <EditText
        android:id="@+id/kolomTakaran"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:hint="isisisisisisi"
        android:inputType="number"
        android:textSize="14dp"
        android:visibility="invisible" />

</RelativeLayout>

hope somebody could help me..thanks :D .. sorry for my bad english

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

These settings are required:

In the UI code:

expListView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);

In the AndroidManifest.xml for the Activity:

activity android:name=".YourActivity" android:windowSoftInputMode="adjustPan"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...