how to display value of textbox on same screen in android application just like whatsaap

拥有回忆 提交于 2019-12-02 08:14:47

I think, you can use a ListView insted of scroll view. and add list items from the chat text value dynamically. call notifydatasetchanged() every time when you add a new item to it.

<TextView
    android:id="@+id/username"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:gravity="center_vertical"
    android:layout_alignParentTop="true"
    android:textColor="#000000"
    android:text="aakash"
    android:background="#c0c0c0"
/>

<ListView
                android:id="@+id/listView_chats"
                android:layout_width="match_parent"
                android:layout_height="100dp"
                >
            </ListView>


<EditText
    android:id="@+id/chattxt"
    android:layout_width="230dp"
    android:layout_height="45dp"
    android:hint="type here"
    android:inputType="textMultiLine" />

<Button
    android:id="@+id/sendbtn"
    android:layout_width="75dp"
    android:layout_height="45dp"

    android:text="Send" />

</LinearLayout>

Write a custom adapter for the listView and add the code to manage the list data.

i got the answer to my question

import android.R;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class ButtonActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_button);


    }
     public void setText(){
            Button myButton = (Button)findViewById(R.id.button1);
            final TextView myText = (TextView)findViewById(R.id.text1);
            final EditText myInput = (EditText)findViewById(R.id.edit);
            myButton.setOnClickListener(new OnClickListener() {

                public void onClick(View arg0) {
                    myText.setText(myInput.getText()); 
                }
            });    
        }

    }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!