2016-03-06 32 views
0

我正在制作一个应用程序,用户在editText中写入并单击按钮,以便写入的数据以textview形式出现。 现在,当另一个用户在同一个editText中写入数据时,数据应该出现在另一个textview中,等等。多次从editText获取数据

如何从多个文本浏览中的相同编辑文本中获取数据?

+0

你从EditText上的字符串。之后,您希望将TextView应用于其中。所以有什么问题? –

+0

到目前为止你写了什么?它有助于理解你的问题的细节(例如,你是否有工作代码来为一个'TextView'传输文本,但不是更多?是否在XML中预先定义了'TextView',或者是否以编程方式创建它们?等等) – PPartisan

回答

0

为此,您必须知道已键入的文本。你可以把它们存储和数组列表

ArrayList<String> list = new ArrayList<String>(); 

,当用户触摸按钮可以检查输入与列表中。

if (list.contains(input)) { 
    // do sth 
} else { 
    // do ther stuff 
} 

这里是您的解决方案,同时增加文本视图:

如果我们假设你的布局是这样的:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:id="@+id/info" 
android:layout_height="wrap_content" 
android:orientation="vertical"> 
</LinearLayout> 

if (list.contains(input)) { 

    View linearLayout = findViewById(R.id.info); 
    //LinearLayout layout = (LinearLayout) findViewById(R.id.info); 

    TextView valueTV = new TextView(this); 
    valueTV.setText(input); 
    valueTV.setId(5); 
    valueTV.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); 

    ((LinearLayout) linearLayout).addView(valueTV); 


} else { 
    // do other stuff 
} 

注:不是将它们添加到视图,您可以将其添加到一个列表视图。这将是更好的 http://developer.android.com/guide/topics/ui/layout/listview.html

http://www.mkyong.com/android/android-listview-example/