列表视图中的范围不显示最小值和最大值的搜索栏 [英] Listview not displaying min and max values in Range seek bar

查看:276
本文介绍了列表视图中的范围不显示最小值和最大值的搜索栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建2个拇指和显示最小和最大值一个TextView导引头吧。因此,我请参考本教程的 https://开头code。 google.com/p/range-seek-bar/#Example_usage_as_Integer_range

然而,在运行时,TextView的不当拇指被拖动改变。我的项目是由2个java活动的。如附后的主要活动和RangeSeekBar.java这是作为tutorial.Kindly征求你的意见完全一致。

MainActivity.java

 包com.example.doubleseekbar;
进口android.app.Activity;
进口android.content.Context;
进口android.os.Bundle;
进口android.util.Log;
进口android.view.LayoutInflater;
进口android.view.Menu;
进口android.view.ViewGroup;
进口android.widget.TextView;进口com.example.gto_doubleseekbar.RangeSeekBar.OnRangeSeekBarChangeListener;公共类MainActivity延伸活动{    私人TextView的TextView的;
    受保护的静态最后弦乐TAG =com.example.doubleseekbar;    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);
        TextView的=(的TextView)findViewById(R.id.textView1);        //创建RangeSeekBar 20和75之间的整数范围
        RangeSeekBar<整数GT;搜索栏=新RangeSeekBar<整数GT;(20,75,本);        seekBar.setOnRangeSeekBarChangeListener(新OnRangeSeekBarChangeListener<整数GT;(){
                @覆盖
                公共无效onRangeSeekBarValues​​Changed(RangeSeekBar<>酒吧,整数minValue(最小值),整数maxValue(最大值)){
                        //处理更改范围值
                    字符串powerranger =用户选择新的范围值:MIN =+ minValue(最小值)+,MAX =+包括maxValue;
                    Log.i(TAG,powerranger);
                    textview.setText(powerranger);                }
        });        //添加RangeSeekBar至pre定义布局
        LayoutInflater吹气=(LayoutInflater)getApplicationContext()。getSystemService
                (Context.LAYOUT_INFLATER_SERVICE);
        ViewGroup中布局=(ViewGroup中)inflater.inflate(R.layout.activity_main,NULL);
        layout.addView(搜索栏);
        的setContentView(布局);    }    @覆盖
    公共布尔onCreateOptionsMenu(菜单菜单){
        //充气菜单;如果是present这增加了项目操作栏。
        。getMenuInflater()膨胀(R.menu.main,菜单);
        返回true;
    }}

activity_main.xml中

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:paddingBottom会=@扪/ activity_vertical_margin
    机器人:paddingLeft =@扪/ activity_horizo​​ntal_margin
    机器人:paddingRight =@扪/ activity_horizo​​ntal_margin
    机器人:paddingTop =@扪/ activity_vertical_margin
    工具:上下文=MainActivity。>    <的TextView
        机器人:ID =@ + ID / textView1
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentLeft =真
        机器人:layout_alignParentTop =真
        机器人:layout_marginTop =193dp
        机器人:文字=范围值要改变这里/>< / RelativeLayout的>

您的反馈真的很感激。


解决方案

   - >给ID您activity_main.xml中
- >的setContentView(布局)为什么要叫两次?从这些删除的行
   code所以你的code应该如下

activity_main.xml中

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:ID =@ + ID / root_view----->>这是你的主要布局的ID
    机器人:paddingBottom会=@扪/ activity_vertical_margin
    机器人:paddingLeft =@扪/ activity_horizo​​ntal_margin
    机器人:paddingRight =@扪/ activity_horizo​​ntal_margin
    机器人:paddingTop =@扪/ activity_vertical_margin
    工具:上下文=MainActivity。>      <的TextView
        机器人:ID =@ + ID / textView1
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentLeft =真
        机器人:layout_alignParentTop =真
        机器人:layout_marginTop =193dp
        机器人:文字=范围值要改变这里/>
       < / RelativeLayout的>

MainActivity.java

  @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);        //创建RangeSeekBar 20和75之间的整数范围
        RangeSeekBar<整数GT;搜索栏=新RangeSeekBar<整数GT;(20,75,本);
        seekBar.setOnRangeSeekBarChangeListener(新OnRangeSeekBarChangeListener<整数GT;(){
            @覆盖
            公共无效onRangeSeekBarValues​​Changed(RangeSeekBar<>酒吧,
                    整数minValue(最小值),整数maxValue(最大值)){
                  //处理更改范围值
                 字符串powerranger =用户选择新的范围值:MIN =+ minValue(最小值)+,MAX =+包括maxValue;
                  //Log.i(TAG,powerranger);
                 textView1.setText(powerranger);
            }
        });        //添加RangeSeekBar至pre定义布局
        ViewGroup中布局=(ViewGroup中)findViewById(R.id.root_view);
        layout.addView(搜索栏);
    }

I wanted to create a seeker bar with 2 thumbs and a textview showing the min and max value. Therefore i refer to this tutorial https://code.google.com/p/range-seek-bar/#Example_usage_as_Integer_range?.

However, during runtime, the textview does not change when the thumbs is being dragged. My project is made up of 2 java activity. Main activity as attached below and RangeSeekBar.java which is exactly the same as in the tutorial.Kindly seek your 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.

解决方案

->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>

In 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);
    }

这篇关于列表视图中的范围不显示最小值和最大值的搜索栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆