I want to have an EditText
in Android which I can see the previous input in rounded box with the ability to remove it. Besides, I can write a new input and save it like the following image.
-
1I would recommend you to check this library: https://github.com/qiugang/EditTag – Amiraslan Jun 24 '17 at 14:01
-
1Visit Android Arsenal. Search for Material Chips, Chip View, Tags, there are many solutions. – Juan Jun 24 '17 at 14:04
-
thanks,but actually I want these Chipviews to be shown inside an EditText with the ability to add more. – Atieh mn Jun 24 '17 at 14:19
1 Answers
You may use nested views and add them dynamically. You don't have to show the tags in the EditText, instead, you could try to make a layout that contains the EditText and add TextViews dynamically into it. You can set a boarder as the background for the layout. You may define the border in the res/drawable folder and assign it to the layout that contains the tags and your EditText. And it would look like the picture you provided. The border.xml could be like this, you may play with the params:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke android:width="2dp"
android:color="#80FFFFFF" />
<corners android:radius="5dp" />
</shape>
Then you need to define the layout of the 'rounded box', we name it layout_tag.xml, which can be a simple LinearLayout with a customised background, i.e. the box. It should be very similar to the way you decorate the outer layout. The layout_tag.xml may contain a TextView. You may also add an ImageView or a button with the delete icon after the TextView and wrap these two views in your layout_tag.xml.
Then you need to add them dynamically into the search field layout, which you could find plenty of posts to help, such as: Android: add a TextView to LinearLayout programatically.
In the above link, you may adjust the first piece of code block to your layout_tag.xml. The second piece of code tells you how to add the layout_tag dynamically into your outer layout, i.e. the container of the Tags.
At last, you can wire this up whenever a user submits a tag, also remember to add an OnClickListener on the delete image/button.

- 71
- 9
-
2could you read line by line. All the necessary code is in there, either directly or via the link. If you have further doubts, please be more specific. – CristianoYL Jun 25 '17 at 22:22