2

I have a ListView with a TextView (which has an integer as string) and a Seekbar. I need to extract the integer value and set it to the Seekbar.

Unfortunately, when I do this, I get a NullPointer exception because the content that populates the ListView item is not recognized by the onCreateView of the PlaceholderFragment.

String progressValue = percentileTextView.getText().toString();
bar.setProgress(Integer.parseInt(progressValue));

I have an activity layout for this activity, then a fragment layout which contains the listview and then I have a content.xml where the actual TextView is present. My question is how to reference this TextView? Am I doing this right, i.e. Activity layout contains a ConstraintLayout with Toolbars etc, then the Fragment Layout contains the ListView and I am using a separate content.xml and applying that to the ListView via a SimpleAdapter.

 newAdapter = new SimpleAdapter(getContext(), newList,
                                R.layout.content, new String[] {
                                    "name",
                                    "percent"
                                },
                                new int[] {
                                    R.id.name1, 
                                    R.id.percentile1
                                });

I hope you understand my problem.

When I do the following, it works (i.e. Android Studio understand that is the TextView) - but throws a null pointer exception upon build.

TextView percentileTextView = (TextView) rootView.findViewById(R.id.percentile1);

UPDATE 1 for pskink:

Newlist contents:

[{TA=Item1, IA=46}, {TA=Item2, IA=98}, {TA=Item3, IA=70}, {TA=Item4, IA=54}, {TA=Item5, IA=99}, {TA=Item6, IA=98}]

Row item layout (content.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="wrap_content"
    android:orientation="vertical"
    android:padding="@dimen/activity_horizontal_margin">
    <TextView
        android:id="@+id/name1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="2dip"
        android:textStyle="bold"
        android:textColor="@color/colorAccent" />
    <RelativeLayout
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:padding="5dp">
    <TextView
        android:id="@+id/greater_than"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#5d5d5d"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:text="@string/greater_than" />
        <TextView
            android:id="@+id/percentile1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#5d5d5d"
            android:layout_toRightOf="@id/greater_than"
            android:layout_toEndOf="@id/greater_than"
            android:textStyle="bold" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#5d5d5d"
        android:layout_toRightOf="@id/percentile1"
        android:layout_toEndOf="@id/percentile1"
        android:text="@string/percentile_text"/>


    </RelativeLayout>
    <SeekBar
        android:id="@+id/seekBar2"
        android:paddingTop="12dip"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="end|bottom"
        android:paddingTop="12dip"
        android:orientation="horizontal">
        <ImageView
            android:contentDescription="info"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/someimg" />
    </LinearLayout>

</LinearLayout>
Maytham Fahmi
  • 31,138
  • 14
  • 118
  • 137
Zac
  • 695
  • 1
  • 11
  • 34
  • Add your error log. – Mohamed Mohaideen AH Dec 24 '17 at 07:46
  • Please show an example about the viewbinder with seekbar. There is no error log, just the seekbar is null, because it can't find it from the row item xml. Also my percent data for the seekbar is in an ArrayList hashmap and that explains the "name", "percent" keys (of the hashmap) shown in the question. – Zac Dec 24 '17 at 08:40
  • Hi, I have added the newlist contents and the item layout - PLEASE check. – Zac Dec 24 '17 at 18:50
  • I have. As you can see, I am passing values from ArrayList to ListView items. – Zac Dec 24 '17 at 19:38
  • TA's value is name, IA's value is percent... The ListView works well. I am talking about, how to extract IA's values after it's loaded to the ListView (or before) and use those values to setProgress on a Seekbar. – Zac Dec 24 '17 at 20:04
  • Sorry I don't understand the ViewBinder. – Zac Dec 25 '17 at 17:40

0 Answers0