EditText上,看起来像TextView的一个ListView内 [英] EditText that looks like TextView inside a ListView

查看:146
本文介绍了EditText上,看起来像TextView的一个ListView内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是<一个href=\"http://stackoverflow.com/questions/9000630/is-this-is-ok-to-use-the-listview-for-inline-editing\">developing应用,用户可以在的ListView 编辑数据。我想有一个的EditText 的ListView的里面,这EditText上应做的TextView但是,当用户点击它,它应该看起来像的EditText ,我怎么能实现这个功能?

I am developing an application where the user can edit the data in the ListView. I want to have an EditText inside that ListView, this edittext should behave like TextView but when the user clicks it it should look like EditText, How can i achieve this functionality?

其实在ListView内的EditText长相丑陋和放大器;我想,在EditText上应该看起来像一个TextView bydefault但是当用户尝试编辑数据,那么它看起来应该像EditText上。

Actually the EditText inside the ListView looks ugly & i want that the EditText should look like a TextView bydefault but when the user try to Edit the data then it should look like the EditText.

我希望我的问题是清楚的,如果不是请询问。

I hope that my question is clear if not please ask.

推荐答案

下面的文件,我在我的应用程序使用。

The below files I used in my app.

的main.xml 在布局文件夹

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"    
    android:orientation="vertical" >
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />
    <EditText android:layout_width="fill_parent"
        android:padding="5dip"
        android:layout_height="wrap_content"
        android:textColor="#00f"
        android:textSize="20dip"
        android:background="@drawable/bg" />    
    <EditText android:layout_width="fill_parent"
        android:padding="5dip"
        android:layout_height="wrap_content"
        android:textColor="#00f"
        android:textSize="20dip"
        android:background="@drawable/bg" />
</LinearLayout>

myshape.xml 在绘制文件夹

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">   
    <solid   android:color="#fff"/> 
    <corners android:radius="2dip" />   
    <stroke android:width="2dip"
        android:color="#ff4500" />
</shape>

bg.xml 在绘制文件夹

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >    
    <item android:state_enabled="true"        
        android:state_focused="true"                        
        android:drawable="@drawable/myshape"/>    
</selector>

的Java文件

public class EditTextSelector extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

这篇关于EditText上,看起来像TextView的一个ListView内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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