inserting textview inside edittext in android? - android

I am trying to insert a textview inside a Edittext as in below
can anyone pls give me ideas about how to implement it or something.
thanks :)
update:
the textviews in the edittext will vary dynamically.

Try this sample code. It fits your requirement.
PopupWindow pw = new PopupWindow(
this.getViewInflate().inflate(R.layout.pw_layout,
null, true, null),
100,100,true);
// display the popup in the center
pw.showAtLocation(layout, Gravity.CENTER, 0, 0);
pw.update(20,20,100,100);
For the views inside EditText part, you 'll have to extend the EditText. Overview of how it should look is as follows.
class emailEditText extends EditText {
List<NamePhotoView> ViewlistOfSelectedContacts; // create new
void addContact(String name, Bitmap photo) {
// create a new 'NamePhotoView' and add to the ViewlistOfSelectedContacts
}
#Override
void onDraw(Canvas canvas) {
for (....) {
// draw all views from the list. left to right.
}
// you have to some how offset the text start coordinate. then call super
super.onDraw(canvas);
}
}

I think you cannot set TextView inside EditText.
But alternatively you can make it look that way. Here are the steps
convert textview to BitmapDrawable
convert bitmap drawable into SpanableString (ImageSpan)
then set this returned SpannableString to your EditText
I have recently completed this kind of ui and i have explained in my blog Making GoSmsPro/Evernote like EditText

The way Android implements it, the so called Chips UI, can be found here.
Essentially it's a custom span that draws the components (image, text, etc.) over the text, plus some logic to show the popup.

you can create a component based on what you need like you mentioned above with frame layout. You may have a FrameLayout or RelativeLayout with two views such as EditText and TextView while text view is on top of EditText. also you can put image view if you want in right like your picture.
Although you don't need to create a component and easily you can do this in your XML layout, if you have plan to use it regularly through your application it is good practice to create those views as a component.

Related

How to Implement EditText in ListView like a Tree view in Android

I am working with android development and want to implement edittext in listview such like that in picture. now want to add this kind of implementation. is there any way to do exactly this thing or any library which is doing this work.any kind of help will be appreciated and thanks an advance.
It's pretty simple. I recommend you not to use listview to implement that. Just use LinearLayout with vertical orientation, and add each field when the "Add More" button item clicked.
LinearLayout parentLayout = (LinearLayout) findViewById(R.id.parent_layout); //make sure you have set vertical orientation attribute on your xml
TextView addMoreText = new TextView(context);
addMoreText.setText("Add More");
addMoreText.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
EditText editTextItem = new EditText(context);
parentLayout.addView(editTextItem, 0);
}
});
parentLayout.addView(addMoreText);
Note that the code above is just global picture of how to solve your problem. For implementation with close or add button on the right side, you may create custom view that holds EditText, ImageView based your own.

Custom textview with rotate, zoom in,zoom out and move on touch in android?

Any buddy have Custom Text View with Rotate, Zoom In, Zoom Out & Move functionality like MutiTouch Image View like this http://judepereira.com/blog/multi-touch-in-android-translate-scale-and-rotate/ in android?
I Want exactly like this screen shots.
1. In that screen draw simple text.
2. In that screen when i zoom this view Text auto wrap.
3. In that screen Move Text on view.
4. In that screen Rotate Text.
This all functionality do on TextView touch.
I used https://github.com/jcmore2/Collage to achieve a rotated textview
but i changed the whole code since the plugin works with images
CardView extends ImageView
i chnaged to MyCardView extends RelativeLayout then removed all the code related to images
and instead of using collage.createCollageResources(listRes);
i created my own function in my own CollageView class
public void createCollage(List<MyCardView> list) {
for (MyCardView layout : list) {
addCard(layout);
}
}
Now in the Activity you can add to the collageview a complete RelativeLayout with it's children not just images
this also will allow dealing with single view or multiple .. TextView or any thing else .. finally this will make the view not just rotated but dragged and zoomed with multi touch gesture.
Yes you can create it see below image and follow Here.
ImageView: To add ImageView
// add a stickerImage to canvas
StickerImageView iv_sticker = new StickerImageView(MainActivity.this);
iv_sticker.setImageDrawable(getResources().getDrawable(R.drawable.c10));
canvas.addView(iv_sticker);
TextView: To add TextView
// add a stickerText to canvas
StickerTextView tv_sticker = new StickerTextView(MainActivity.this);
tv_sticker.setText("nkDroid");
canvas.addView(tv_sticker);
However, build this did an awesome job.

Handling an EditText that was added programatically

I've been making all of my views dynamically, and now I've come to the point where I want to add an EditText for people to write in.
I've been able to accomplish this for the most part, but it doesn't look right. I have a linear layout that I'm adding a relative layout to. I'm making the relative layout have a white background, then adding the EditText. Problem is, it always adds it to the direct center of the relative layout, and options to align it vertically to the top have so far failed.
I also need to be able to pull the text from it later when a separate button was pressed (I know how to make the button work, it's the pulling text from it part I'm a bit iffy on). Here's my code so far:
public void addEditText(LinearLayout L){
EditText myEditText = new EditText(c);
myEditText.setSingleLine(false);
RelativeLayout l1 = new RelativeLayout(c);
LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(scWidth1, 300);
lp.gravity=Gravity.CENTER;
l1.setLayoutParams(lp);
l1.setBackgroundColor(Color.WHITE);
l1.setGravity(Gravity.CENTER_VERTICAL);
l1.addView(myEditText);
L.addView(l1);
}
l1.setGravity(Gravity.CENTER_VERTICAL); places the EditText in center vertical of the parent container i.e RelativeLayout, remove that line.

How to add blocks of linearLayouts and is there a better way?

This is the main idea of what I am trying to do.
I would like to ask you what is the best way to make such a design. the problem is that these gray/black blocks might not show up (user will choose which should show up). So I would like to find out do I need to make these 3 text views inside linearLayout programatically? Is there anyway to create some sort of template which I would only have to edit by setting new texts for textViews and add them to some sort of layout?
Another option is to just have a LinearLayout and an xml for the row entry. Then you can do:
LinearLayout layout = (LinearLayout) this.findViewById(R.id.your_layout_id);
List<Blocks> userBlocks = getMyUserBlocks();
for(Block b : userBlocks) {
View blockView = LayoutInflater.from(getBaseContext())
.inflate(R.layout.your_row_layout, layout, false);
TextView someData = (TextView) blockView.findViewById(R.id.your_text_view_id);
someData.setText(b.someAttribute.toString());
layout.addView(blockView);
}
You will need a separate xml layout for the block row.
You can use a ListView with large dividers. Your dark gray blocks are the row views, and you can just append them to a dataset and update the adapter for the ListView. For the dividers, see setDivider() and setDividerHeight().

Refresh all view in android?

I working on messaging platform like whatsup.When ı send message ı must update the screen because ı am getting data in db.When i press send button ı must update View.
I googled but ı can not exact solution.Can anybody help me?
EDIT:
my code:
RelativeLayout layout=new RelativeLayout(this);
LayoutParams lparams = new LayoutParams(
1200,LayoutParams.WRAP_CONTENT);
layout.setLayoutParams(lparams);
//layout.setBackgroundResource(R.drawable.bubble);
// Creating a new TextView
TextView tv = new TextView(this);
tv.setText(msgdesc[i]);
layout.setGravity(Gravity.RIGHT);
tv.setPadding(30, 10, 0, 0);
layout.addView(tv);
bubbleLayout.addView(layout);
You will need to call either requestLayout() or invalidate() depend on what you update exactly in your view
If you just need the View to redraw so call invalidate()
If you change the View bounds (e.g. size) call requestLayout()
if you use a listview with a listadapter, then you have to use listadapter.notifyDataSetChanged(); this will update your listview with the new data
Have you try with view.invalidate()? http://developer.android.com/reference/android/view/View.html
Drawing
Drawing is handled by walking the tree and rendering each view that
intersects the invalid region. Because the tree is traversed in-order,
this means that parents will draw before (i.e., behind) their
children, with siblings drawn in the order they appear in the tree. If
you set a background drawable for a View, then the View will draw it
for you before calling back to its onDraw() method.
Note that the framework will not draw views that are not in the
invalid region.
To force a view to draw, call invalidate().
you can try like the reply in this post invalidate the viewgroup:
How to force an entire layout View refresh?
Finally if you have only a TextView in your layout try this:
//Supposing that msgdesc is a class field.
void myRefreshFunction(RelativeLayout l)
{
if(l != null)
{
l.removeAllViews();
TextView tv = new TextView(this);
tv.setText(msgdesc[i]);
layout.setGravity(Gravity.RIGHT);
tv.setPadding(30, 10, 0, 0);
layout.addView(tv);
}
}
see Dianne's answer:
invalidate() just causes the views to be redrawn: http://developer.android.com/reference/android/view/View.html#invalidate()
requestLayout() asks that the views go through a new measure/layout pass (and then redraw): http://developer.android.com/reference/android/view/View.html#requestLayout()
If you're building a messaging app and items are added to some kind of list, I suggest using a RecyclerView and Recyclerview Adapter to achieve what you're trying to do. When the list grows in size, your relative layout won't be scrollabe, a RecyclerView however would. On top of that RecyclerView gives you more performance with very long list because from the name ~Recycle~rView, it recycles previous items and thus increases preformance.
Here's a reasonable tutorial on how to achieve what you want:
https://blog.sendbird.com/android-chat-tutorial-building-a-messaging-ui
(I'm not affiliated with SendBird or anything, it's just the first result when you google: RecyclerView chat example)

Categories

Resources