0

I'm trying to make a popup window where you can read and write some comments (like on facebook app). It works well but When I select the Edit text the soft keyboard hides the edit text so I cannot see what i'm writing.I tried the solution that I found in most of similar topics, I have added this line in my activity in manifest:

        android:windowSoftInputMode="stateVisible|adjustResize"/>

But it's not working.

here is some of my code:

    private PopupWindow popWindow;

    public void onShowPopup(View v){

    LayoutInflater layoutInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    // inflate the custom popup layout
    final View inflatedView = layoutInflater.inflate(R.layout.comments_popup_layout,null);
    // find the ListView in the popup layout
    ListView listView = (ListView)inflatedView.findViewById(R.id.commentsListView);

    // get device size
    Display display = getWindowManager().getDefaultDisplay();
    final Point size = new Point();
    display.getSize(size);



    // fill the data to the list items
    setSimpleList(listView);


    // set height depends on the device size
    popWindow = new PopupWindow(inflatedView, size.x - 200,size.y - 500, true );
    popWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.comments_bg));
    // make it focusable to show the keyboard to enter in `EditText`
    popWindow.setFocusable(true);
    // make it outside touchable to dismiss the popup window
    popWindow.setOutsideTouchable(true);

    // show the popup at bottom of the screen and set some margin at bottom ie,
    popWindow.showAtLocation(v, Gravity.BOTTOM, 0,100);
     }

     void setSimpleList(ListView listView){

    ArrayList<String> contactsList = new ArrayList<String>();

    for (int index = 0; index < 10; index++) {
      contactsList.add("I am @ index " + index + " today " + Calendar.getInstance().getTime().toString());
    }

    listView.setAdapter(new ArrayAdapter<String>(ListEddystoneActivity.this,
            R.layout.comments_list_item, android.R.id.text1,contactsList));
  }



    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <LinearLayout
        android:id="@+id/headerLayout"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:orientation="horizontal"
        android:layout_alignParentTop="true"
        android:gravity="center">

        <TextView
            android:layout_gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Some One and 20 Others Like this"
            android:textColor="@color/black"
            android:textStyle="bold"
            android:layout_margin="5dp"/>
    </LinearLayout>

    <ListView
        android:id="@+id/commentsListView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="5dp"
        android:layout_below="@id/headerLayout"
        android:paddingBottom="50dp"
        android:layout_marginBottom="0dp"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:id="@+id/writeCommentView">

        <EditText
            android:id="@+id/writeComment"
            android:hint="Write a Comment"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:textSize="12dp"
            android:textColor="@color/black"
            android:background="#00000000"/>
    </LinearLayout>

</RelativeLayout>
    </ScrollView>

Thank you :)

Aymane Bo
  • 59
  • 2
  • 11
  • It's sounds like maybe you mean implement an auto complete editText? – visionix visionix Jun 08 '16 at 08:24
  • thanks visionix, I don't understand what you mean by "auto complete editText", but what I want to do is a popupwindow with a list view and an editText. – Aymane Bo Jun 08 '16 at 08:35
  • http://www.tutorialspoint.com/android/android_auto_complete.htm scroll to the bottom and see if this is the functionality you are looking for – visionix visionix Jun 08 '16 at 08:41
  • yes exactly, but in this example the edit text is displayed in the layout of the main activity, in my case it's in a PopupWindow :/ and I think that's why the adjustResize does not work for me. – Aymane Bo Jun 08 '16 at 09:17
  • it not displayed in the layout, it is a popup on top of the activity layout – visionix visionix Jun 08 '16 at 09:19
  • aah you're talking about the autocomplete text view ! no in my project, the popupWindow include all of the list view (for the comments) AND the text field. – Aymane Bo Jun 08 '16 at 09:38

1 Answers1

0

ScrollView should have only on child most probably linearLayout.

        <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true">

          <LinearLayout 
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

          <RelativeLayout 
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:id="@+id/headerLayout"
                android:layout_width="match_parent"
                android:layout_height="30dp"
                android:orientation="horizontal"
                android:layout_alignParentTop="true"
                android:gravity="center">

                <TextView
                    android:layout_gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Some One and 20 Others Like this"
                    android:textColor="@color/black"
                    android:textStyle="bold"
                    android:layout_margin="5dp"/>
            </LinearLayout>

            <ListView
                android:id="@+id/commentsListView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_margin="5dp"
                android:layout_below="@id/headerLayout"
                android:paddingBottom="50dp"
                android:layout_marginBottom="0dp"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:orientation="vertical"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:id="@+id/writeCommentView">

                <EditText
                    android:id="@+id/writeComment"
                    android:hint="Write a Comment"
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:textSize="12dp"
                    android:textColor="@color/black"
                    android:background="#00000000"/>
            </LinearLayout>

          </RelativeLayout>
     </LinearLayout>
   </ScrollView>
Sohail Zahid
  • 8,099
  • 2
  • 25
  • 41