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

Multiple scans/intents delivered to receiving Activity
Using SQLiteOpenhelper inside another class - Does not call OnCreate()
How to intent to url from non activity class?
Proguard with Unity3d return error code 1
Layout design and detect inside click of image - Android [closed]
Error with method, only after adding other unrelated code
Combine two images into one orientation issue
Cannot instantiate the type GalerieAdapter
Admob doesn't record impression
Bitmap memory management in Android OOM
Complete overwrite of current version of android app with update
Listen for Container Edges when dragging an ImageView
How to create layout withminimum and maximum height?
Generating XML stream in Android
android webview copy url with Long Press
how to add several images in a listview after getting their names from the sqlite database

Categories

HOME
batch-file
algorithm
nunit
jsf-2.2
socket.io
r-googlesheets
xbee
square
opengl-3
elasticsearch-5
pega
mod-security
x-cart
jsonpath
android-7.0-nougat
bourbon
symbols
dpdk
mongoid6
interpreter
strongname
fragment-backstack
firebase-analytics
datastax-enterprise-graph
browser-sync
mql
vex
ntp
autodesk-designautomation
recurring-events
complex-numbers
pdw-file-browser
lubridate
ods
typesafe-config
c9.io
attributeerror
softmax
android-exoplayer
xmldocument
photos
serde
hammer.js
dbcontext
opengl-4
flyout
trigger.io
cmp
hadoop-2.7.2
pacemaker
uicolor
mapinfo
delta
cassia
redis-cluster
tfs-workitem
ess
uvc
android-broadcast
document-repository
insight.database
jquery-slider
dot42
buffering
ora-06550
model-driven-development
octal
actiondispatch
mantle
event-receiver
codebase
commerceserver2007
hbm2java
lalr
asynchronous-wcf-call
soappy

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