I have a ExpandableListView that works properly with JSONObject. When I click on group, the children are showed. Children represent comments and, in my case, the last child is ever a EditText. By this EditText I can insert a new comment. The problem is this:
if in my adapter I use myEditText.requestFocus() the keyboard works, I mean when I type on it editText is update with characters, but often I have to push more than once on EditText to see the keyboard. If in my adapter I don't use myEditText.requestFocus(), when I click on EditText I can see the keyboard quickly (as normally the keyboard appears when you click on EditText), but if I type, the editText doesn't update, I mean I don't see any characters in the widget. To see the characters I have to click one more time on EditText while keyboard is opened.
This is the layout I use for comments:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layoutchildren"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical"
android:paddingLeft="10dip"
android:paddingLeft="10dip"
android:background="@color/lgray">
<RelativeLayout android:paddingLeft="10dip" android:paddingRight="10dip" android:background="@color/white" android:layout_height="45dip" android:layout_width="fill_parent" android:layout_marginBottom="2dip" >
<ImageView android:id="@+id/feedcommentcell_profileimg" android:layout_width="32dip" android:layout_height="32dip" android:layout_centerVertical="true" android:scaleType="fitXY"/>
<TextView android:id="@+id/feedcommentcell_username" android:textStyle="bold" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="13sp" android:textColor="@color/black" android:layout_toRightOf="@+id/feedcommentcell_profileimg" android:layout_marginLeft="10dip" android:layout_alignTop="@+id/feedcommentcell_profileimg"/>
<TextView android:id="@+id/feedcommentcell_comment" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="11sp" android:textColor="@color/black" android:layout_toRightOf="@+id/feedcommentcell_profileimg" android:layout_marginLeft="10dip" android:layout_below="@+id/feedcommentcell_username"/>
<TextView android:id="@+id/feedcommentcell_scanhour" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="10sp" android:textColor="@color/dgray" android:layout_alignParentRight="true" android:layout_alignBottom="@+id/feedcommentcell_username"/>
</RelativeLayout>
</LinearLayout>
This is layout for my EditText
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:background="@color/lgray">
<RelativeLayout android:id="@+id/feedcell_addcomment" android:paddingLeft="10dip" android:paddingRight="10dip" android:paddingTop="5dip" android:paddingBottom="5dip" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="0.5dip" android:background="@color/mlgray">
<EditText android:id="@+id/feedcell_edittxt" android:textColor="@color/black" android:layout_width="fill_parent" android:hint="Write a comment.." android:layout_height="35dip" android:textSize="14sp" android:gravity="center_vertical" android:paddingLeft="10dip" android:background="@drawable/bgfriendsedtxt" android:singleLine="true" android:clickable="true"/>
<Button android:id="@+id/feedcell_commentbtn" android:textColor="@color/black" android:textSize="14sp" android:layout_height="32dip" android:layout_width="60dip" android:text="Done" android:layout_alignParentRight="true" android:layout_marginTop="4dip" android:layout_marginRight="5dip" android:gravity="center"/>
</RelativeLayout>
</LinearLayout>
this is my getChildView in my adapter:
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
{
View v = convertView;
int type=getChildType(groupPosition,childPosition);
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (v == null)
{
switch(type)
{
case TYPE_EDIT:
v = vi.inflate(R.layout.edittextcommentlist,null);
break;
case TYPE_CHILD:
v = vi.inflate(R.layout.feedcommentcell,null);
break;
}
}
try
{
if(type == TYPE_CHILD)
{
final JSONObject o = getChild(groupPosition,childPosition);
if(o!=null)
{
//I fill out my Children XML file
}
}
else if(type==TYPE_EDIT)
{
JSONObject o = getChild(groupPosition,childPosition);
if(o!=null)
{
final int groupPos=groupPosition;
addComment = (EditText)v.findViewById(R.id.feedcell_edittxt);
addComment.requestFocus();
addComment.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
addComment.setText("");
}
});
//addComment.requestFocus();
commentBtn=(Button)v.findViewById(R.id.feedcell_commentbtn);
commentBtn.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
//I write my code for button..ok
}
});
}
}
}
catch(Exception e)
{}
return v;
}
I found a lot of answers about this topic, but I tried to change the state of the keyboard on android manifest, I tried to implement onFocusChange, I tried to add in xml file or by java code attributes android:focusable and android: focusableInTouchMode .. . I noticed that if I don't use addComment.requestFocus(), when I click on the EditText, the keyboard opens quickly but the Done button turns after 1 second and becomes return .. In short I have tried so many ways but I can not solve the problem. Can someone help me? thanks