android - Insert views in HorizontalScrollView programatically -
I am creating a chat app that looks like this (dummy view):
XML ; The activity is exactly as they are
& Lt; / HorizontalScrollView & gt; & Lt; ImageButton android: id = "@ + id / message" Android: layout_width = "75dp" Android: layout_height = "75dp" Android: layout_alignParentBottom = "true" Android: layout_alignParentRight = "true" android: src = "@ drawable / Aisi_lancr" /> & Lt; / RelativeLayout & gt; I want to add a view to HorizontalScrollView (HSV). I have read that HSV can have only 1 child (mostly linerlight) & amp; Ideas should be added for this. This is the view that I want to add: & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" Android: layout_width = "75dp" Android: layout_height = "75dp" Android: Orientation = "Vertical" Android: Background = "# 454545 "& Gt; & Lt; ImageView Android: id = "@ + ID / profile picture" Android: layout_width = "60dp" Android: layout_height = "60dp" /> & Lt; AutoCompleteTextView Android: layout_width = "75dp" Android: layout_height = "wrap_content" /> & Lt; / LinearLayout & gt; This is my activity:
Public class increases the main activity activity (ImageButton sendIB; HorizontalScrollViewMessageHSV; Liner LayoutLLICIDHSV; see the child; LayoutInflat Flatr: @ override protected void saved create (bundled Instansstet) {Suprknkret (saved Instensstet); requestWindowFeature (Window.FEATURE_NO_TITLE); setContentView (R.layout.activity_main); Inflater = (LayoutInflater) it KgetSystemService (reference LAOUT_INFLATER_SERVICE); Chche = inflater.inflate (r. Let Ksbd_aliment, empty, false); SendIB = (ImageButton) findViewById (R.id.send); ChatMessageHSV = (HorizontalScrollView) findViewById (R.id.chat_message_HSV); LLinsideHSV = (LinearLayout) findViewById (R.id.LL_inside_HSV); chatMessageHSV.setOnClickListener (new OnClickListener () {// is the trigger never @Override public void onClick (View arg0) {Toast.makeText (MainActivity.this, "HSV", Toast .LENGTH_SHORT) .show ();}}); lLinsideHSV.setOnClickListener (New OnClickListener () {// This is never triggered @Override Public Zero onClick (see arg0) {Toast.makeText (MainActivity.this, "ll ", Toast.LENGTH_SHORT) .show ();}}); SendIB.setOnClickListener (New OnClickListener () {@Override Click Public Zero (see ARG0) {lLinsideHSV.addView (child);}}); } // end of onCreate} Note: I want to add ideas to the HSV click.
Q-1: I'm unable to click on HSV or to trigger the linear layout below. I tried to do a touch event but the incident was triggered 4-5 times on every touch.
Q-2 Click the I Click Button button (to use only) Once I am able to insert the scene once, it says an exception:
java.lang.IllegalStateException: The specified child already has a parent. You must first call the removeView () on the parent of the child Then how do I insert ideas again?
Question 2: You must create a new child
children = inflater .inflate (r.lay.word_limment, empty, inaccurate); on every click event:
@ override onclick (see child = inflater.inflate (...); LLinsideHSV.addView (child); }
Comments
Post a Comment