android


How to use another layout id?


In my application I have used one alert box.. In this alert box, I give another layout to be show.. using setView() method.. I have a problem. How to use layout elements id in my activity?
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.volume, null);
builder.setTitle("Volume");
builder.setView(layout);
builder.setPositiveButton("OK", null);
builder.setNegativeButton("Cancel", null);
AlertDialog alert1 = builder.create();
alert1.show();
This code shows you how to show a custom alert and get a view from that custom layout:
AlertDialog mDialog = null;
Context mContext = getApplicationContext();
final AlertDialog.Builder my_Dialog = new AlertDialog.Builder(this);
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.my_dialog, (ViewGroup) findViewById(R.id.layout_root));
ImageView imageViewInsideLayout = (ImageView) layout.findViewById(R.id.imageviewLayout);
my_Dialog.setView(layout);
mDialog = my_Dialog.create();
mDialog.show();
Something like this:
In your activity:
....
View layout = inflater.inflate(R.layout.volume, null);
.....
View some = layout.findViewById(YOUR_VIEW_ID);
.....
if you want to refer to view inside your custom layout, then do the following:
EditText editText = (EditText) layout.findViewById(R.id.your_editText);
Button editText = (Button) layout.findViewById(R.id.your_button);
.
.
.
//and so one with other views
You can get reference to view by builder.findViewById( R.id.restart );

Related Links

How to put button on the bottom of Scrollview
How to fix “Failed to get UI hierarchy” issue while recording espresso test in android studio
Cannot Detect Alt-beacon in android
Initializing value to views in ActionBar Tab framents in android while onCreate of Tab Activity
Android Navigation Drawer Design Library on child activity bug
Firebase Datasnapshot returns null [duplicate]
Cannot use Android Crop image crop library in Android
How to sort SDCard image based on date in android
I want to add Validation for inputName , inputPrice before upload to the database
How to resolve android studio installation error(“Your android studio installation is corrupt and will not work properly.”)?
How to auto hide toolbar in webview fragments
Gradle-only solution to modify App name based on Build Variant
Android change recycler view column no. on pinch zoom
Download files from google drive to Xamarin Android Player
How to add a notification to a MediaPlayer Service?
Search in Firebase based on distance

Categories

HOME
asp.net-web-api
beautifulsoup
localization
awk
gpu
formal-languages
powerpoint
zend-framework
interface
devise
cublas
nuget-package
android-json
trac
rcloud
openstreetmap
owin
ibeacon-android
mautic
jsonpath
flatpak
qsqlquery
docx
symfony-2.8
powershell-v5.0
nodemcu
bourbon
gmm
replication
babel
cgbitmapcontext
dpdk
string-concatenation
imageresizer
aggregation
expressionengine3
angular-translate
bringtofront
iis-express
constexpr
turfjs
gnat-gps
hunspell
wurfl
jvmti
comparison-operators
doc
watchface
skylink
facebook-social-plugins
ovf
dotnet-httpclient
netbeans6.8
x-ray
singleinstance
opengl-4
skin
check-mk
pybrain
gameplay-kit
taocp
pacemaker
async.js
iotivity
nikeplus-api
jodd
jtwig
google-query-language
aurora
project-organization
contentcontrol
concept-insights
rasterize
boomerang
forwarding
iced-coffeescript
wso2greg
omnifaces
snackbar
fits
openbabel
beatsmusic
mruby
jbake
iiop
addressing-mode
rmysql
xml-dsig
functional-java
dot42
twitter-bootstrap-rails
windows-embedded-standard
ora-06550
breakout
away3d
windows-phone-8-sdk
script#
scringo
actiondispatch
booksleeve
extreme-programming
extconf.rb
usertype
google-maps-mobile
xui
unattended-processing
django-paypal
silent
drupal-fivestar
strtod
skype4java
linfu-dynamicproxy
xslcompiledtransform

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App