What I want is simple, well at least I thought it would be simple. I just want a window where an EditText is on the bottom of the screen, and the rest of the space is filled with ListView. Unfortunately, it did not work as I expected. What I want is the following image. Is there any easy way to do this in the XML, or should I write some special code for this?
My Problematic Android Source Code.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ListView android:id="@+id/demolist" android:layout_width="match_parent" android:layout_height="fill_parent" android:layout_weight="1" > </ListView> <EditText android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0"> </EditText> </LinearLayout >
Try this: my_listview. setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { } });
This example demonstrates how do I dynamically update a ListView in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
ListView uses Adapter classes which add the content from data source (such as string array, array, database etc) to ListView.
What you Want
Last Visible Item Without Keyboard
Last Visible Item With Keyboard
Last Visible Item With larger input
Here is how i did it.
Summary
Details
Activity
<activity android:name="MainActivity" android:screenOrientation="portrait" android:windowSoftInputMode="adjustPan"></activity>
Chat View
<RelativeLayout android:id="@+id/chat_header" android:layout_width="fill_parent" android:layout_height="40dp" android:padding="3dp" > <Button android:id="@+id/btnBackChat" android:layout_width="35dp" android:layout_height="35dp" android:layout_alignParentLeft="true" android:background="@drawable/back_button" /> <TextView android:id="@+id/txt_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/btnBackChat" android:layout_centerHorizontal="true" android:textColor="@android:color/white" android:textSize="18sp" /> <ImageView android:id="@+id/imgViewProfileChat" android:layout_width="35dp" android:layout_height="35dp" android:layout_alignParentRight="true" /> </RelativeLayout> <ListView android:id="@+id/listView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_above="@+id/form" android:layout_below="@+id/chat_header" android:stackFromBottom="true" android:transcriptMode="alwaysScroll"/> <RelativeLayout android:id="@+id/form" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:orientation="vertical" > <ImageButton android:id="@+id/btnAttach" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:contentDescription="@string/attach" android:src="@drawable/attach_icon" /> <EditText android:id="@+id/txtChat" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_toLeftOf="@+id/btnSend" android:layout_toRightOf="@+id/btnAttach" android:inputType="textMultiLine" android:maxLines="4" /> <Button android:id="@+id/btnSend" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:text="@string/send" /> </RelativeLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With