I am very new to Android.
Is it possible to implement a TextBox , Button and a dynamic list inside popup in Android.
Please help me in this.
Thanks.
Yes you can make a custom dialog of your own.
I've used following code in my java file
Dialog add_themedialog = new Dialog(addthemecontext);
add_themedialog.setContentView(R.layout.add_new_theme);
add_themedialog.setTitle("Add New Theme");
final EditText et_entertheme = (EditText)add_themedialog.findViewById(R.id.et_dialog_addtheme);
Button btn_addtheme = (Button)add_themedialog.findViewById(R.id.btn_dialogaddtheme);
Button btn_canceltheme = (Button)add_themedialog.findViewById(R.id.btn_canceltheme);
The xml file add_new_theme contains a textbox,an edittext and 2 buttons..
Ask me if any thing is not clear or if you want complete source code for it. :-)
Related
I am coding the functionality of a button that serves to remove other buttons. My buttons are dynamic. I have to program the functionality in my .kt. I am noob on android studio so am not sure what the best way to do it.
The function is like this:
I have a TableRow where are my buttons. All this buttons have their own listener.
val param: TableRow.LayoutParams =TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,TableRow.LayoutParams.MATCH_PARENT)
var buttondynamic = Button(this)
buttondynamic = buildButton(item, i, mysize, mysize, true)
buttondynamic.layoutParams = param
tr.addView(buttondynamic)
Also I have a listener for the trash button but I don't know how to make the action works. How I should code this? Hove you some idea?
trashButton.setOnClickListener {
// This for goes over the table taking every single button
for(i in 1..12){
val btnFor: Button = findViewById(i) as Button
... -> here the codo shoul be (I think)
}
}
On the other hand, I have the code for the delete button listener. I only need the idia for the remove button over a button.
Thank you so much
If you want to delete it for just the current view , mean that you want it to appear the next time you open that activity , so just set its visibility like :
button.Visiblity = View.GONE
But if that buttons is connected to some stored data , like an array or a list or something like that , you can just delete that stored data for that button and reload your table again .
I have the ability to make my own popup, with dialogs, but I don't need anything complex. I was wondering if there was a simple function I could call that would make a popup where the user entered text and then return to me that text for use.
Sorta like these popups
But with one where the user would enter text.
Fairly new so if there is something like this I wouldn't mind an example to go with it. Thanks.
If you are using Android native UI, then you can easily create an AlertDialog and add a EditText to the dialog.
EditText et = new EditText(this);
AlertDialog.Builder ad = new AlertDialog.Builder (this);
ad.setTitle ("Type text");
ad.setView(et); // <----
ad.show();
I'm creating a scenario test framework for Android Cordova/PhoneGap applications that builds on JUnit. There is one scenario I would like to test: you click on some button in the webpage (shown in an Android WebView) and it opens a popup (an AlertDialog). I want to check the message on this popup and click one of the buttons. Therefore I need the view object of this AlertDialog.
I know you can use findViewById, but you have to give an id as parameter, which I don't have since the dialog is created with the following code:
AlertDialog.Builder dlg = new AlertDialog.Builder(ctx.getContext());
dlg.setMessage(message);
dlg.setTitle(title);
....
dlg.create();
dlg.show();
Any idea how I can access the correct view?
Thanks!
The TextView containing the AlertDialog's message is always identified by android.R.id.message. If you capture the result of dlg.create(), you should be able to get a reference to the message TextView by calling .findViewById(android.R.id.message) on it, from which you could then get the text.
I want to input data i.e. name and age of user on a scene of AndEngine. How can I do that ??
I dont want to use a dialog for this purpose.
You asked this on the AndEngine forums and RealMayo gave you the best answer there.
Study the TextBreakExample.java - and more specifically, study the AndEngineExamples/res/layout/textbreakexample.xml file
You will see how to "blend" a standard Android EditText (not a dialog) into your game.
If all you want to do is a text entry overlay, you can add it in your onSetContentView() method:
#Override
protected void onSetContentView() {
editTextExample = new EditText(this);
this.addContentView(editTextExample, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT));
}
Otherwise, if you want to make editable text whose look can be set by AndEngine, check out the example Java code and XML code
am new to android
I have seen many examples on creating buttons, but i just can't get what does each line mean :(
take the following piece of code as an ex.
connect = (Button) findViewById(R.id.button_connect)
connect.setOnClickListener(connectListener)
private OnClickListener connectListener = new OnClickListener() {
public void onClick(View v) {
Log.i("CONNECT PRESSED", "press")
// ....
// ....
// ....
};
what i know is that the first line Defines a button, but wht is findViewbyId?
i know the second line
but then when defining the listener, what's the log.i?
nd r "connect pressed" and "press" just labels for the button? f so why there r two for a single button...
You should have an additional Button connect; before those lines.
connect = (Button) findViewById(R.id.button_connect) // findViewById() in layman term it means, finding view by id. Which also means finding the view(button/textview/edittext) by ID(value you stated in your main.xml for the view. e.e. android:id=#+id/"")
connect.setOnClickListener(connectListener) //listens to a click when clicked
private OnClickListener connectListener = new OnClickListener() { //if button of android:id="button_connect" is clicked, Do this method.
public void onClick(View v) {
Log.i("CONNECT PRESSED", "press") //prints message in your logcat
// ....
// ....
// ....
};
If you still don't understand what does findViewById(), just think of it this way. View is man. Id is name. So in the end you are finding the man by name("Whatever this is")
In Android you normally define the layout of an Activity in an XML file. Each View element in a layout that you want to interact with in code needs an id. In you example the layout XML file needs to have a button with the id button_connect.
In the onCreate() method of an Activity you normally call setContentView() and pass it the layout you want to use in this Activity. E.g. setContentView(R.layout.my_layout); where your layout file's name is my_layout.xml.
The setContentView() method builds up the defined layout as objects and with findViewById(R.id.button_connect) you get a reference to a Button object from this layout whose id is button_connect.
Log.i() is simply logs the message "press" under the tag "CONNECT PRESSED" in the log cat.
It seem to be you didn't read basic things about android app development. Android Developers website providing information to learn android app development with good examples and tutorials. You are asking very basic things by just copying the code from tutorials.
Actually its not the right place for this kind of questions. First do practice by reading tutorials around the web.
Coming to your doubts regarding code you posted here, those are very basic things.
findViewById() finds a View by field Id, which is declared in XML layout file as below
Log.i() is LogCat info message displayed in your logcat window when debugging is enabled in your app.
in your example you probably have defined an xml layout file as the style of your activity with setContentView(R.layout.myXMLLayout);
If not, findViewById(R.id.button_connect) will fail.
R.id.button_connect refers to an id created in your xml layout.
There has to be a line android:id="#+id/button_connect" in a < Button > tag.
findViewById finds this Button (which is more genereally a view, which is why you have to cast it to a Button with the (Button) before findViewById(...) ). You then refer to exactly the button you've put in your xml.
Log.i("CONNECT PRESSED","press"); isn't necessary at all. It's just logging the press of the button and displays it in the log cat. It can be removed without any further impact. This is for debugging only and should be removed for any final (public) versions of your code.