的EditText在Java永久的提示 [英] EditText with a permanent hint in Java

查看:125
本文介绍了的EditText在Java永久的提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的EditText 在它的一些信息。当没有信息,
我使用的显示字幕 setHint()

 最后的EditText信息=新的EditText(活动);
如果(data.getinfo()= NULL和放大器;!&安培;!。data.getAddress()修剪()等于()){
    info.setText(data.getinfo());
}其他{
    info.setHint(R.string.info);
}

我要表明标题即使的EditText 的信息,该信息应该是下方字幕。

我试着用的setText()。但是,这并不能工作。

 如果(条件){
    info.setText(R.string.info);
    info.setText(data.getinfo());
}其他{
    info.setHint(R.string.info);
}


解决方案

在一个 RelativeLayout的,使用的TextView 作为覆盖查看之上的的EditText 。使用适当的颜色,大小,字体,实现你正在寻找的效果。

下面是一个提示

 < RelativeLayout的...>
    < EditText上机器人:ID =@ + ID /名称
        机器人:layoutWidth =match_parent
        机器人:layoutHeight =WRAP_CONTENT>    < TextView的机器人:ID =@ + ID / name_hint
        机器人:layoutWidth =WRAP_CONTENT
        机器人:layoutHeight =WRAP_CONTENT
        机器人:重力=左| center_vertical
        机器人:layout_alignLeft =@ ID /名称
        机器人:layout_alignRight =@ ID /名称
        机器人:layout_alignTop =@ ID /名称
        机器人:layout_alignBottom =@ ID /名称
        机器人:layout_alignBottom =@ ID /名称>
< / RelativeLayout的>

这仅仅是一个起点,可以调整高度的的EditText ,定位您的TextView ,变化其重力等,以达到你所期待的。

I have an EditText with some information in it. When there is no information, I'm displaying a caption using setHint().

final EditText info = new EditText(activity);
if (data.getinfo() != null && !data.getAddress().trim().equals("")) {
    info.setText(data.getinfo());
} else {
    info.setHint(R.string.info);
}

I want to show that caption even if the EditText has info, the info should be below the caption.

I tried using setText(). But that didn't work either.

if (condition) {
    info.setText(R.string.info);
    info.setText(data.getinfo());
} else {
    info.setHint(R.string.info);
}

解决方案

Within a RelativeLayout, use a TextView as an overlay View on top of your EditText. Use appropriate colors, size for the font to achieve the effect you are looking for.

Here is a hint

<RelativeLayout …>
    <EditText android:id="@+id/name" 
        android:layoutWidth="match_parent"
        android:layoutHeight="wrap_content" >

    <TextView android:id="@+id/name_hint" 
        android:layoutWidth="wrap_content"
        android:layoutHeight="wrap_content"
        android:gravity="left|center_vertical"
        android:layout_alignLeft="@id/name"
        android:layout_alignRight="@id/name"
        android:layout_alignTop="@id/name"
        android:layout_alignBottom="@id/name"
        android:layout_alignBottom="@id/name" >
</RelativeLayout>

This is just a starting point, you can adjust the height of your EditText, position your TextView, change its gravity, etc., to achieve what you are looking for.

这篇关于的EditText在Java永久的提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆