Listview does not display minimum and maximum values ​​in a range search bar

I wanted to create a search bar with two thumbs and a text image displaying the minimum and maximum value. Therefore, I refer to this tutorial https://code.google.com/p/range-seek-bar/#Example_usage_as_Integer_range ?.

However, at run time, the text image does not change when you drag the thumbs. My project consists of two java operations. The main activities below are RangeSeekBar.java, which is exactly the same as in the tutorial. Seek advice.

MainActivity.java

package com.example.doubleseekbar;


import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.gto_doubleseekbar.RangeSeekBar.OnRangeSeekBarChangeListener;

public class MainActivity extends Activity {

    private TextView textview;
    protected static final String TAG = "com.example.doubleseekbar";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textview = (TextView) findViewById(R.id.textView1);

        // create RangeSeekBar as Integer range between 20 and 75
        RangeSeekBar<Integer> seekBar = new RangeSeekBar<Integer>(20, 75, this);

        seekBar.setOnRangeSeekBarChangeListener(new OnRangeSeekBarChangeListener<Integer>() {
                @Override
                public void onRangeSeekBarValuesChanged(RangeSeekBar<?> bar, Integer minValue, Integer maxValue) {
                        // handle changed range values
                    String powerranger = "User selected new range values: MIN=" + minValue + ", MAX=" + maxValue;
                    Log.i(TAG, powerranger);
                    textview.setText(powerranger);

                }
        });

        // add RangeSeekBar to pre-defined layout
        LayoutInflater inflater = (LayoutInflater)getApplicationContext().getSystemService
                (Context.LAYOUT_INFLATER_SERVICE);
        ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.activity_main,null);
        layout.addView(seekBar);
        setContentView(layout);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="193dp"
        android:text="Range value to be change here" />

</RelativeLayout>

Really grateful for your feedback.

0
1
->Give id your activity_main.xml 
-> setContentView(layout) why you are calling two times ?? Remove these line from your                    
   code so your code should look like below

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/root_view"   ----->>this is id of your main layout
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

      <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="193dp"
        android:text="Range value to be change here" />
       </RelativeLayout>

MainActivity.java

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

        // create RangeSeekBar as Integer range between 20 and 75
        RangeSeekBar<Integer> seekBar = new RangeSeekBar<Integer>(20, 75, this);
        seekBar.setOnRangeSeekBarChangeListener(new OnRangeSeekBarChangeListener<Integer>() {
            @Override
            public void onRangeSeekBarValuesChanged(RangeSeekBar<?> bar,
                    Integer minValue, Integer maxValue) {
                  // handle changed range values
                 String powerranger = "User selected new range values: MIN=" + minValue + ", MAX=" + maxValue;
                  //Log.i(TAG, powerranger);
                 textView1.setText(powerranger);
            }
        });

        // add RangeSeekBar to pre-defined layout
        ViewGroup layout = (ViewGroup) findViewById(R.id.root_view);
        layout.addView(seekBar);
    }
0

Source: https://habr.com/ru/post/1528054/


All Articles