android


Dynamic edittext not showing up text in an Android app


Creating a dynamic EditText as follows
EditText myText = new EditText(this);
myText.setId(ctrlKey);
myText.setBackgroundResource(R.drawable.style_edittext);
myText.setClickable(true);
myText.setCursorVisible(true);
myText.setTextColor(Color.BLACK);
myText.setTextSize(12);
myText.setText("may i"); //pageField.getValue());
myText.setSelection(0);
myText.setCursorVisible(true);
if (pageField.getMultiline()) {
myText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
}
else
myText.setSingleLine(true);
//myText.setEnabled(false);
pageLayout.setLayoutParams(ctrllp);
pageLayout.addView(myText, ctrllp);
Edittext is created and visible at appropriate location, but I can't see the text in the Edittext, and when I try a place cursor in it, it seems like there is already text in the Edittext (the cursor position and help words shown below confirms). Even if I type something in the Edittext also not visible.
XML
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.topazsystems.pdoc.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<include
android:id="#+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
layout="#layout/toolbar" />
</android.support.design.widget.AppBarLayout>
<com.topazsystems.pdoc.ZoomableViewGroup
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity = "center_horizontal|center_vertical"
android:id="#+id/zoomLayout"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="fill"
android:id="#+id/RelLayout">
<include layout="#layout/content_main" />
</RelativeLayout>
</com.topazsystems.pdoc.ZoomableViewGroup>
<include layout="#layout/fragment_navigation"/>
</android.support.design.widget.CoordinatorLayout>
In activity oncreate I am calling a method which contains the control rendering code.
pageLayout = (RelativeLayout) findViewById(com.topazsystems.pdoc.R.id.RelLayout);
//to display page controls during appload
pageControlsList = pdfRenderer.GetPageControls();
if (pageControlsList != null) {
if (pageControlsList.size() > 0) {
generateControls();
//fillDefaultDocControls();
mfrg.showPage(pdfRenderer.getmCurrentPageNum(), true, this);
}
}
where generatecontrols() contains the edittext creation code and mfrg is instance of fragment.
Check once removing background resource if it is the culprit. so remove the following line and check if text is visible.
myText.setBackgroundResource(R.drawable.style_edittext);
You have passed wrong context in EditText , you need to pass context of parent of EditText like below code.
in your code you are added EditText into pageLayout.
EditText myText = new EditText(pageLayout.getContext());

Related Links

Icons in TabLayout
Android Action Bar not showing
Error install ionic cordova
TextWatcher in Android
Fix textview at the top and button at the bottom of LinearyLayout
Scrollbar for multiple linear layout view in android
Start APP after Installation via android.provider.Telephony.SMS_RECEIVED [duplicate]
Changing language in run time with Preferences [android]
Youtube API in android
Android replace checkbox style with custom drawable selector
create Widget & Error in android studio
Cloudant replicate all data in android
Augumented Reality with Locations Library (iOS/Android)
Save SWITCH button state, and recover state with SharedPrefs
How get all image in folder in my site to listview?
Android, Style ActionBar with Background Image & Background Colour

Categories

HOME
scikit-learn
cheerio
ng-idle
swt
oracle-apex-5
seo
echo
code-coverage
elasticsearch-5
windows-ce
ycsb
azure-iot-hub
intershop
exit
resourcebundle
jasmine-node
user-defined-functions
mql
xbox
glib
laravel-eloquent
biztalk-rule-engine
sharding
arduino-ide
browser-extension
navigator
salesforce-communities
mcustomscrollbar
doc
dbnull
movilizer
http-request
xmldocument
puredata
pom.xml
tinymce-3
openblas
context-sensitive-grammar
oracleclient
bootstrap-tags-input
juice-ui
reachability
iotivity
mapinfo
expectations
tooleap
udpclient
query-by-example
project-organization
fuzzywuzzy
httpruntime.cache
jaunt-api
concurrentmodification
android-launcher
lasso
viola-jones
git-ftp
aspectj-maven-plugin
mraid
uvc
ejb-2.x
packet-sniffers
android-cookiemanager
insight.database
grails-plugin-rabbitmq
mutual-authentication
radiant
synapse
light
solace-mq
isqlquery
windows-phone-8-sdk
printdialog
twisted.web
alice
device-width
vfs
thttpd
update-statement
event-receiver
codebase
squishit
folding
lxr
asynchronous-wcf-call
great-circle

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App