I would have thought this is pretty simple but I've tried several things and it doesn't work. Basically, when activity starts I want my edit text to be invisible (I'm doing this by making size to 0dp, width and height).
Then, the idea is when user types on softkeyboard, the size changes, and user can see the editText and what is being typed.
Here's my code :
MainActivity.java
package com.example.chris.sunil_gupta;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.provider.CallLog;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ListView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
//create a ListView object called listview
ListView listview;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listview = (ListView) findViewById(R.id.ListView_2);
final EditText editText = (EditText) findViewById(R.id.editText);
editText.requestFocus();
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (editText.length() > 0) {
//Your query to fetch Data
// editText.getLayoutParams().width=32;
// editText.getLayoutParams().height=50;
editText.setWidth(32);
editText.setHeight(50);
}
}
});
}
}
Layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
tools:context=".MainActivity">
<ListView android:id="@+id/ListView_2"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="@color/black"
android:layout_weight="1">
</ListView>
<EditText
android:layout_width="0dp"
android:layout_height="0dp"
android:id="@+id/editText"
android:background="@null"
android:inputType="phone">
<!--android:visibility="invisible"-->
</EditText>
</LinearLayout>
Sorry,change to this: