Android :: Android - Showing Dialog From Custom Component
Jun 15, 2010
I am writing a custom component (derived from a relative layout) which has to show a dialog. Is there a way to do this using callbacks like oncreatedialog or onpreparedialog? if not: if i have to create the dialog outside oncreatedialog, i have to "attach it to an Activity with setOwnerActivity(Activity)". How can the custom component access the activity it is used in, when it is used in the activity's xml-layout and not created from code?
View 1 Replies
Feb 7, 2010
I encountered a message like below when opening a custom dialog through menu option.
02-07 16:37:45.478: ERROR/BACKGROUND_PROC(1007): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
Using the latest sdk with 1.5 emulator.
View 7 Replies
View Related
Aug 18, 2010
I'm wondering how I can create a custom pop-up like the one in the screenshot below (borrowed from the Swype keyboard), where I can have a couple of buttons, which each commit a string to the currently "connected" TextView (via a InputConnection). Please note: this is an InputMethodService and not an ordinary Activity. I already tried launching a separate Activity with Theme:Dialog. However, as soon as that one opens I lose my focus with the TextView and my keyboard disappears (and with that my InputConnection is gone).
View 3 Replies
View Related
Sep 2, 2010
I have a really weird problem, which I am unable to debug so far. thing is. my app needs to download something to work. So in the beginning of the onCreate() method, I check if that something is already downloaded. If not, I pop a dialog up asking the user to download it.My dialog is shown and I am clicking, so aManager.install() is called. I am passing the context because that aManager.install() pops up a ProgressDialog to show downloading progress and spawns a new thread in which everything is downloaded. So obviously before creating my dialog I make a Handler to receive the response from that aManager.install(). And the response MAY vary, because for example the internet connection isn't available (Exception raised and catched and listener called with different code).Now, when that happens (Exception) I would like to call another dialog saying "something went wrong, would you like to retry?" so another call to showDialog(DIALOG_REINSTALL) (this time with another code).thing is the showDialog() gets called (I can verify this by logging) but the dialogs doesn't show up. Instead my application JUST HANGS Does someone have a clue why it's doing this? No exception raised, absolutely nothing from logcat, I can't tell WHERE it's hanging...just see that the method is called and the dialog should be displayed.
View 2 Replies
View Related
Dec 29, 2009
I want to make a custom Dialog,because i donot like it"s style,i want get a rounded rectangle rather than rectangle . i know to implement it by theme in Manifest.xml . for example :the code
at activity write:
CODE:............
My question is how to implement this Similar result by extends dialog or alertDialog.
View 1 Replies
View Related
Jul 9, 2010
I have created a simple class named Panel which extends the SurfaceView class and does some drawing in the onDraw method. When I use it from the code it works fine. For example this works as expected:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new Panel(this)); ....
However when I try adding this component from an xml layout the program crashes:
XML file (main.xml):
<?xml version="1.0" encoding="utf-8"?> <org.anddev.Panel android:id="@+id/panel" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"/>
Code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);....
Error msg: Sorry!
The application Test (process org.anddev) has stopped unexpectedly. Pleas try again.
I can not figure out why the same class works when created in one way and doesn't work when created in another.
View 3 Replies
View Related
Mar 29, 2010
I'm trying to create a component using an xml layout file. I defined a layout with some custom attributes. This layout is inflated when user add it inside another layout. My problem is I don't know the parent, so I pass null for the parent viewgroup when I call inflate method. I think that's the reason why I see anything in my view. Do you know how can I do (I don't want to redefine onDraw method because I use existing component). Below my xml layout and my custom class.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView android:id="@+id/img_btn_option" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<TextView android:id="@+id/txt_btn_option" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_toRightOf="@id/img_btn_option"
android:textColor="@color/font_white" android:textStyle="bold"/>
</RelativeLayout> public class ButtonOptionsView extends View {
public ButtonOptionsView(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater li =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout vg =(RelativeLayout)li.inflate(R.layout.button_option, null);
TypedArray ta = getContext().obtainStyledAttributes(attrs,R.styleable.ButtonOption);
((ImageView)vg.findViewById(R.id.img_btn_option)).setImageResource(ta.getResourceId(R.styleable.ButtonOption_image,0));
((TextView)vg.findViewById(R.id.txt_btn_option)).setText(ta.getResourceId(R.styleable.ButtonOption_text,0));}
View 4 Replies
View Related
Dec 8, 2009
I've made a little test component that overrides ImageView, called myImageView, and prints some text and an arrayList of Doubles over whatever image is specified in the related xml. However, right now, the text and Doubles that are drawn over the image are defined within the myImageView class. Is there a way to pass the data from the main onCreate function to the myImageView class before the layout is drawn?
I'm new to OO programming, but based on my understanding of this:
http://developer.android.com/guide/topics/ui/custom-components.html
It's possible because ImageView is just like any other class. This leaves me with two initial guesses:
1. I could generate my test data in the main onCreate, and store it in the array's xml file, and then read that xml file with myImageView,
OR
2. I could extend view instead of ImageView, but because of my new- ness, then I would lose the ability to use it in an xml layout sense - and that's what I really want.
View 2 Replies
View Related
Dec 9, 2009
I've prepared custom component based on LinearLayout. Whole component is defined in XML. Currently to use it you have to write:
<com.xxx.android.components.TopMenu
android:layout_width="fill_parent"
android:layout_height="44dp" />
Is it possible to set width and height in the java constructor? So it would be possible to write just:
<com.xxx.android.components.TopMenu />
I've tried to modify and set LayoutParams, but it didn't work for me.
View 1 Replies
View Related
Aug 16, 2009
I've created custom compound component and observe very strange exception (google says nothing about it). Custom component rare exception: Parser is not a BridgeXmlBlockParser!
It is very simple:
public class MyTabber extends LinearLayout {
.. public MyTabber(Context context) { super(context);
Init(context); }
View 2 Replies
View Related
Jun 12, 2010
I have made a Custom Component in XML, consisting of a button with an imageview stacked on top of it:
<myapp.widget.ClearableCaptionedButton
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/ccbutton_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|left"
android:textAppearance="?android:attr/textAppearanceMedium"
android:background="@android:drawable/edit_text"/>
<ImageView
android:id="@+id/ccbutton_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dip"
android:layout_alignRight="@id/ccbutton_button"
android:layout_alignTop="@id/ccbutton_button"
android:layout_alignBottom="@id/ccbutton_button"/>
</myapp.widget.ClearableCaptionedButton>
Extract of java source code:
public class ClearableCaptionedButton extends RelativeLayout implements OnClickListener {
...
public ClearableCaptionedButton(Context context, AttributeSet attrs) { super(context, attrs);
// some stuff that works fine
} ..
protected void onFinishInflate() { super.onFinishInflate();
mButton = (Button) findViewById(R.id.ccbutton_button);
mClear = (ImageView) findViewById(R.id.ccbutton_clear);
mButton.setText(""); // error here: mButton == null
}
My problem is similar to this one. When I try to find the views inside the custom compound, findViewById returns null. But, as you can see, i already added super(context, attrs); to the constructor. I am using the custom component directly in xml layout, like this:
<LinearLayout>
<!-- some stuff -->
<myapp.widget.ClearableCaptionedButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
app:caption="to"/>
</LinearLayout>
View 1 Replies
View Related
Jun 11, 2010
I'd like to create a custom component which supports voice recognition. (Custom Component which displays voice recognition button if available). It will primarily be an extended EditText which should show the microphone button for voice recognition if it is available. I wanted to to look at the search app-widget on the homescreen but I don't find it in the source. This is intended to use the voice recognition as some sort of dictation device, i.e. the user does not have to type but use his voice instead. So could anyone please point me in some direction?
View 1 Replies
View Related
Nov 5, 2010
I'm developing a small application in with a list view filled with a compound component. This component has two text view and one button inside. One of the text view is invisible and when the button is clicked it should appear. I can show the list but i can't make the textview visible when the button is clicked. Here is the xml of the component: And this is the ArrayAdapter that fills the list:
public class AddressAdapter extends ArrayAdapter { int resource;
RelativeLayout placeView;
EditText addressText;
public AddressAdapter(Context _context, int _resource, List _items) {
super(_context, _resource, _items);
resource = _resource;
} private OnClickListener buttonClick = new OnClickListener() {
public void onClick (View v) {
int i = placeView.findViewById(R.id.stub_import).getVisibility();
visibility(i);
} };
private void visibility(int i) {
// TODO Auto-generated method stub switch(i) {
case(View.GONE): { addressText.setVisibility(View.VISIBLE);
} case(View.VISIBLE): { addressText.setVisibility(View.GONE);
} } }
@Override public View getView(int position, View convertView, ViewGroup parent) {
Item item = getItem(position);
String name = item.getName();
String address = item.getAddress();
if (convertView == null) {
placeView = new RelativeLayout(getContext());
String inflater = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater vi = (LayoutInflater)getContext().getSystemService(inflater);
vi.inflate(resource, placeView, true);
} else { placeView = (RelativeLayout) convertView;
} TextView nameText = (TextView)placeView.findViewById(R.id.placeNamwView);
Button button = (Button)placeView.findViewById(R.id.Button01);
addressText = (EditText)placeView.findViewById(R.id.placeAddressText);
button.setOnClickListener(buttonClick);
nameText.setText(name);
addressText.setText(address);
return placeView;
} }
View 2 Replies
View Related
Oct 29, 2009
The app I'm working on has 4 tabs, 3 of which share many features, including a navigation bar a the bottom with Back, Edit, and Map buttons. There is exactly the same xml in all 3 layouts, so I'm trying to DRY this out by extracting that xml into a separate component, including it, and then going from there. Previously I had:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/showedit_toolbar" style="@style/showItemToolbar">
<ImageButton android:id="@+id/show_person_back_button"
style="@style/blackToolbarButton"
android:src="@drawable/left_white_arrow"
android:layout_alignParentLeft="true"/>
<Button android:id="@+id/show_person_map_button"
style="@style/blackToolbarButton"
android:text="map" android:layout_alignParentRight="true"/>
<Button android:id="@+id/show_person_edit_button"
style="@style/blackToolbarButton"
android:text="edit" android:layout_toLeftOf="@id/show_person_map_button"/>
</RelativeLayout>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_above="@id/showedit_toolbar"
style="@style/CoinLightTheme">
// Lots more layout omitted
I extracted out the bit that's repeated into an xml file called show_toolbar.xml, changing the names of variables to make it more generic across the 3 views
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/show_toolbar" style="@style/showItemToolbar">
<ImageButton style="@style/blackToolbarButton"
android:src="@drawable/left_white_arrow"
android:layout_alignParentLeft="true"
android:id="@+id/show_back_button"/>
<Button android:id="@+id/show_map_button"
style="@style/blackToolbarButton"
android:text="map" android:layout_alignParentRight="true"/>
<Button android:id="@+id/show_edit_button" style="@style/blackToolbarButton"
android:text="edit" android:layout_toLeftOf="@id/show_map_button"/>
</RelativeLayout>
Then from within my original layout file, I replaced that big block of code with
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<include android:id="@+id/show_toolbar" layout="@layout/show_toolbar"/>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:layout_above="@id/showedit_toolbar" style="@style/CoinLightTheme">
Now, the problem is that the view no longer shows up. Including Custom component causes it to be hidden behind main viewI can still click the buttons and they respond (i.e. if I click in the corner where the button should be, it still works), but I cannot see the buttons or bar onto which they were drawn. I cannot find very good documentation on how Include is supposed to work, so perhaps I am using it incorrectly.
View 1 Replies
View Related
Nov 7, 2009
I have a res/layout/main.xml including these elements and others:
<some.package.MyCustomView android:id="@+id/foo" (some other params) />
<TextView android:id="@+id/boring" (some other params) />
In my Activity's onCreate, I do this:
setContentView(R.layout.main);
(TextView) boring = findViewById(R.id.boring);
// ...find other elements...
MyCustomView foo = (MyCustomView) findViewById(R.id.foo);
if (foo == null) { Log.d(TAG, "epic fail"); }
The other elements are found successfully, but foo comes back null. MyCustomView has a constructor MyCustomView(Context c, AttributeSet a) and a Log.d(...) at the end of that constructor appears successfully in logcat just before the "epic fail".
findViewById() returns null for custom component in layout XML, not for other components. Why is foo null?
View 2 Replies
View Related
Sep 23, 2010
I am trying to run example of facebook android sdk , in that i have run stream example to fetch the
data from facebook. Now hen ever i click on "fconnect" button to log in into facebook i am getting following dialog box. so is it possible to replace this dialog box with following to make it simple ?
View 1 Replies
View Related
Apr 25, 2010
I am developing one application for facebook. In this application when user click on login button i start WebView acitvity there user can login. On success of login i start activity from where user pressed that login button.
Now My problem is On main activity I get all friends list from facebook. That takes some time. So i want to show ProgressDialog, however that progress dialog is not showing up in main activity.
Here is my code.
On Login success i am using this method:
CODE:...................
View 2 Replies
View Related
Jun 10, 2010
I have looked at the Android API and other posts here on stackoverflow, but have not been able to figure this out.
My app downloads files to the sd card. I would like to pop a "loading..." dialog while the file is downloading and then have it disappear when the download is finished. This is what i came up with using the android API:
CODE:.............
However the dialog doesn't actually show. when i debug it, it claims that it is showing, but it is obviously not on the screen.
View 2 Replies
View Related
Sep 25, 2009
The Android app I'm currently developing has a main activity that has grown quite large. This is mainly because it contains a TabWidget with 3 tabs. Each tab has quite a few components. The activity has to control of all those components at once. So I think you can imagine that this Activity has like 20 fields (a field for almost every component). Also it contains a lot of logic (click listeners, logic to fill lists, etc). What I normally do in component based frameworks is to split everything up into custom components. Each custom component would then have a clear responsibility. It would contain it's own set of components and all other logic related to that component.
I tried to figure out how this can be done, and I found something in the Android documentation what they like to call a "Compound Control".
(See http://developer.android.com/guide/topics/ui/custom-components.html and scroll to the "Compound Controls" section) I would like to create such a component based on an XML file defining the view structure.
In the documentation it says:
Note that just like with an Activity, you can use either the declarative (XML-based) approach to creating the contained components, or you can nest them programmatically from your code. Well, that's good news! The XML-based approach is exactly what I want! But it doesn't say how to do it, except that it is "like with an Activity". But what I do in an Activity is call setContentView(...) to inflate the views from XML. That method is not available if you for example subclass LinearLayout. So I tried to inflate the XML manually like this:
public class MyCompoundComponent extends LinearLayout {
public MyCompoundComponent(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.my_layout, this);
} }
This works, except for the fact that the XML I'm loading has LinearLayout declared as the root element. This results in the inflated LinearLayout being a child of MyCompoundComponent which itself already is a LinearLayout!! So now we have a redundant LinearLayout in between MyCompoundComponent and the views it actually needs. Can somebody please provide me with a better way to approach this, avoiding having a redundant LinearLayout instantiated?
View 1 Replies
View Related
Oct 5, 2010
I'm reading the android developer docs on creating custom components and one thing that's unclear, is whether you can define the layout of your component using xml and then reuse that across class libraries. like, say for instance, I want to create a class library called myComponents, and in there i want to have myTehAwesumsWidget or whatever, and i want the layout to be defined in xml, can i include that xml in the referenced class library?
View 1 Replies
View Related
Nov 9, 2009
I want to use the speech to text api in android, but I don't want to be slowed down by those dialogs. Is it possible to use the functionality without them?
View 1 Replies
View Related
Sep 12, 2010
I've got an app that responds to an Alert - and I really need to show an alert with a password entry before going on to the next screen; the trouble is I don't seem to be able to show a dialog from a broadcast receiver -- so how can I show a dialog password entry upon receiving an alert?
View 1 Replies
View Related
Oct 30, 2010
In my application i prompt for password in onResume(), and Before this i have already created view in onCreate() so it is compulsory for user to enter password But if user press the Back key password dialog get disappered and user easily use the application. When dialog is Being shown,if get key event for Back key then i can easily handle this for that purpose i implemented onBackPressed()/onKeyDown() methods of Activity But none get event for this key when dialog is on screen after dialog disappered these methods get event for Back key.
View 1 Replies
View Related
Sep 24, 2009
I want to display Dialog Box when the application is launched before loading and launching the activity.
or you can say I want to show the dialog on launcher after the launch of my application.
View 5 Replies
View Related
Feb 2, 2010
I have made an component for Android, which uses two drawables. Using static values for the drawables in the code, the component works but now I want to declare the values in the properties (XML) does anyone know how to do this? Is there a way to do this without using the attrs.xml?
View 1 Replies
View Related
Sep 8, 2009
In my current application I want to show a dialog having "Force Close" and "Report" option at the time of Unhandled Exception. Could anyone please let me know how to have this dialog? right now if I change default Exception Handler to mine It gets control but I am not able to show any dialog after that. I guess UI thread is already closed by the time handler gets control.
View 6 Replies
View Related
Apr 24, 2010
I've got an Android activity which grabs an RSS feed from a URL, and uses the SAX parser to stick each item from the XML into an array. This all works fine but, as expected, takes a bit of time, so I want to use AsyncActivity to do it in the background. The line items = parser.getItems() works fine - items being the arraylist containing each item from the XML. The problem I'm facing is that on starting the activity, the ProgressDialog which i create in onPreExecute() isn't displayed until after the doInBackground() method has finished. i.e. I get a black screen, a long pause, then a completely populated list with the items in. Why is this happening? Why isn't the UI drawing, the ProgressDialog showing, the parser getting the items and incrementally adding them to the list, then the ProgressDialog dismissing?
View 3 Replies
View Related
May 13, 2010
I'm trying to make a custom dialog to show a view in this dialog. This is the Builder code:
//Getting the layout LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_dialog_simple,(ViewGroup) findViewById(R.id.rlDialogSimple));
//Change Text and on click
TextView tvDialogSimple = (TextView) layout.findViewById(R.id.tvDialogSimple);
tvDialogSimple.setText(R.string.avisoComprobar);
Button btDialogSimple = (Button) layout.findViewById(R.id.btDialogSimple);
btDialogSimple.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//Do some stuff
//Here I want to close the dialog
} } );
AlertDialog.Builder builder = new AlertDialog.Builder(AcPanelEditor.this);
builder.setView(layout);
AlertDialog alert = builder.create();
alert.show();
So, I want to dismiss the dialog in the onClick of btDialogSimple. How I can do it? I don't know how to call the dismiss method from inside a onclicklistener. My buttons have a custom layout, so I don't want to make a builder.setPositiveButton.
View 1 Replies
View Related
Sep 9, 2010
I'm getting a NullPointerException while attempting to create a Spinner within a dialog and can't seem to debug it because the code looks solid. Wonder if anyone else has any idea. Any help is greatly appreciated.
protected Dialog onCreateDialog(int id) { Dialog dialog;
switch(id) { case DIALOG_SEND_PM: Spinner spinner = (Spinner)findViewById(R.id.pm_server);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.server_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
dialog = new Dialog(PM.this);
dialog.setContentView(R.layout.send_pm_dialog);
dialog.setTitle(R.string.send_pm);
pmMessage = (EditText) dialog.findViewById(R.id.send_pm_box);
Button sendPm = (Button) dialog.findViewById(R.id.send_pm_button);
sendPm.setOnClickListener(PM.this);
break;
default: dialog = null;
}
I get the exception at adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
I changed the context to MyClass.this and the exception moved down to the next line, which confuses me. I'm wondering if it is the adapter having a null value but I call everything the same way I have before while not in a dialog.
Relevant XML data:
<LinearLayout> <TextView/> <LinearLayout> <TextView/>
<EditText/> <TextView/> <Spinner
android:id="@+id/pm_server"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:background="@drawable/yblueborder"
android:textColor="#ABABAB"/>
</LinearLayout> <Button/> </LinearLayout>
View 1 Replies
View Related
Nov 21, 2009
I spent quite a long time trying to get my first custom dialog box to work, following the example in the Android Dev Guide.
Specifically:
CODE:............
I kept getting a badtokenexception whenever I tried to show the dialog.
Eventually I found a forum posting which suggested changing it to:
new Dialog(this);
Which made the problem go away.
My question is if the example is incorrect, or was the code not intended to be used in an Activity method?
View 3 Replies
View Related