java - how to add rating bar in Linear Layout Dynamically in Android? -


I have tried to add a rating bar to a dynamically linear layout after some text fields. But I'm getting the NullPointerException line = lL.addView (rating); Someone can help me please how to do it. Thanks in advance.

Here's my XML file.

  & lt; ScrollView android: id = "@ + id / scrollField" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: layout_above = "@ + id / btnDELETE" Android: layout_below = "@ + id / textTitle" Android: Layout_marginTop = "10dp" & gt; & Lt; LinearLayout android: id = "@ + id / linearLayoutRatingDetails" Android: Layout_width = "Match_parent" Android: Layout_height = "Wrap_content" android: orientation = "vertical" & gt; & Lt; TextView android: id = "@ + id / tv_EmployeeName" Android: layout_width = "wrap_content" Android: layout_height = "40dp" Android: Layout_marginTop = "L0dp" android: text = "dfkyjrtl" Android: textcolor = "# 2E1F1F" / & Gt; & Lt; TextView android: id = "@ + id / tv_TaskName" Android: layout_width = "wrap_content" Android: layout_height = "40dp" Android: layout_marginTop = "6dp" android: text = "dfkyjrtl" Android: textcolor = "# 2E1F1F" / & Gt; & Lt; TextView android: id = "@ + id / tv_TaskDate" Android: layout_width = "wrap_content" Android: layout_height = "40dp" Android: layout_marginTop = "6dp" android: text = "dfkyjrtl" Android: textcolor = "# 2E1F1F" / & Gt; & Lt; TextView android: id = "@ + id / tv_TaskRate" Android: layout_width = "wrap_content" Android: layout_height = "40dp" Android: layout_marginTop = "6dp" android: text = "dfkyjrtl" Android: textcolor = "# 2E1F1F" / & Gt; & Lt; / LinearLayout & gt; & Lt; / Scrollview & gt; Green my activity code is crate on public void (bundled saved instenstate) {super.naught (savedinstenstate); SetContentView (R.layout.task_details); Intent = getIntent (); Str_IntentName = intent.getExtras (). GetString ("EMP_NAME"); Str_IntentTaskName = intent.getExtras (). GetString ("TASK_NAME"); Str_IntentDate = intent.getExtras (). GetString ("TASK_DATE"); Str_IntentRate = intent.getExtras (). GetString ("TASK_RATE"); NumStar = Integer.valueOf (str_IntentRate); Logs. E ("integer number", "=" + number); FindLL = (Linear Loyalty) VVBIID (RID LinelineLinlighting Details); TvEmpName.setText (str_IntentName); TvTaskName.setText (str_IntentTaskName); TvDate.setText (str_IntentDate); TvRate.setText (str_IntentRate); Create_RatingBar (); } Private Zero Create_RatingBar () {stepSize = (float) 0.5; Rating = New rating time (Task account.); Rating.setNumStars (numStar); Rating.setStepSize (stepsize); LinearLayout.LayoutParams Ultimate = New Linear Line. LayoutParts (Layout Perm WRAP_CONTENT, Layout Para. WRAP_CONTENT); Param.topMargin = 500; Rating.setLayoutParams (Ultimate); LL.addView (rating); }    

To add it to your XML linear layout, For "context" linerlight, you need ID advertising in XML and get an element in this code by using this ID .

  Crate on Public Zero (Bundle SavedInstanceState) {// Some other code for other ideas ViewGroup container = (ViewGroup) findViewById (R.id.linearLayoutRatingDetails); SetupRatingBar Private Controller (ViewGroup RatingsBackConnantier) {Ratings Rating Rating = Rating Rating (Tasks // All sets are required to start in which // SetInmasters (), setStepSize () and Layout parameter ratings. Addewew (ratingbar);}   

Also use more explanatory names "LL" will give you a headache in the future.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -