How to add clickable widgets in EditText at current position - java

I guess the title of the question is clear enough. What I want to do is add clickable widgets like Lable or Button or TextView in an EditText which already has some text in it. These widgets should get appended to the text.
As I don't know the exact number of the widgets to be added at design time, it won't be possible to do it in xml. I must do it in Java.
Thanks in advance.

Views just can be added to ViewGroups and EditText is not a ViewGroup, so you can't do that with default EditText widget, and you can write your own custom View to implement that.
this is the android documentation about custom views, and taking a look at this can be useful too.

Related

how to get value of radio button and display on text view (Java for android)

enter image description here
this the XML structure for the radio button group
i try alot of code but nothnig good
In your Activity you will need to use findViewById to create Views in Java to connect to your layout RadioGroup and TextView. You will need to register a listener on your RadioGroup to detect changes to the selection and then pass the result to your TextView.
Provide the code you've tried and I'll update my answer with specific suggestions to help you fix it.

How to link a new textview created on java with its xml characteristics in android studio?

In Java, I have created a TextView whose text is the string written by the customer on an EditText in a previous activity. In the XML of the activity, I wrote the characteristics I want this TextView to have. My code creates a new TextView without those characteristics, anyone knows how to link them? I attach the java and XML codes. javacode xmlcodeThanks in advance!
You need to define the textview properly.
In oncreate method add
TextView text_message_1;
text_message_1=(TextView) findViewById(R.id.text_message_01);
Then set the text you get from other activity.
Since you are creating a TextView dynamically, so there is no need define a TextView tag in XML. You can simply set properties of that TextView in Java and add it to any ViewGroup or Table or anything you want.
And you can also try using findViewById() method for that TextView.
If you still face any problem, let me know.
I hope it answers well.

How to PERMANENTLY remove layout items in android java

Fairly inexperienced in java still, so I was wondering (as I haven't really found anything useful online) whether there was a way to permanently delete a textview (or any other layout entry, ratingbar etc.) from an android layout in the onclick function.
I want a user to be able to submit a rating only once in every rateable activity, you see.
I have tried everything I can get.
ratingbar.setVisibility(View.GONE);
Works while you're in the activity, yet when you restart again the ratingbar is back. I've also tried:
linearlayout1.removeView( ratingbar );
However, this does the same as
ratingbar.setVisibility(View.GONE);
On reload the ratingbar is back. If anyone can help, that'd be greatly appreciated.
Thanks in advance.
Well you rather choose not to create a view,
than deleting a view that's created.
i guess you could create TextView programmatically
and decide if you want to attach it to your layout or not in java code.
See : Android: Add a textview to linear layout programmatically

Android - how to inflate a view with multiple EditText fields and read their values?

For my Android application, I want to have a view which allows a user to click a plus button to add EditText fields, and next to the EditText fields, I want to have minus buttons that will remove them from the view. In essence, something that is very similar to adding multiple phone numbers/email addresses in the edit Contact interface on Android.
I imagine I will need to do this by inflating my main view with a separate one that contains the EditText and button I want to add each time. However, I have no idea how I will manage identifying each EditText and button with a unique ID, and thus, I have no idea how I would manage to grab the values of each EditText for saving to my database. Can someone advise me on what I need to do? Thank you.
If you have inflated a sub-layout, then you should now have a View object.
You can then call findViewById(R.id.edit_text_1) on that View — assuming that you supplied IDs in the sub-layout XML.
So long as you keep track of each of the parent Views, you can always use findViewById() on them. Or after inflation, if you really want you can set a new, globally-unique ID on each EditText using setId().
You can assign a view widget dynamically, and generate your own ID as it is assigned.
Button b = new Button(this);
b.setId(myId);
Then you can refer back to that widget.
findViewById(myId);

Android Update Layout Content

I'm looking for a way to update a layout's content with a new view. Is there any way to easily do this. It would be similar to how tabs work, but I don't want to have to get into extending the current tab structure if I don't have to.
The final result would be a few buttons that would switch the content in a specific linearlayout for each button.
Any help?
Have a look at ViewSwitcher. This is designed to help with the kind of things you are suggesting.
If you want the contents in entirely different layout files, you can use a LayoutInflater and add the inflated view to the parent view.

Categories

Resources