显示搜索栏的进展,一个TextView自定义警告对话框内 [英] Show progress of seekbar in a textview inside a custom alert dialog

查看:147
本文介绍了显示搜索栏的进展,一个TextView自定义警告对话框内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一个搜索栏和一个TextView自定义警告对话框。我想,当用户使用搜索栏。

I have a custom alert dialog which contains a seekbar and a textview. I want to display progress of seekbar in that textview in percents when the user interacts with the thumb of seekbar..

这是我的code ..

here is my code..

AlertDialog.Builder builder = new AlertDialog.Builder(PrefsActivity.this);
LayoutInflater inflater = getLayoutInflater();
View layoutFromInflater = inflater.inflate(R.layout.dialog_fragment_sensitivity_layout, null);      
builder.setView(layoutFromInflater)
    .setPositiveButton("Ok", new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

        }
    }).setNegativeButton("Cancel", new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });


    final AlertDialog dialog = builder.create();
    dialog.show();

    TextView progress_tv = (TextView) dialog.findViewById(R.id.seekbar_progress_tv2);           
    progress_tv.setText("sdf"); 
    SeekBar seekBar = (SeekBar) dialog.findViewById(R.id.seekBar1); 
    seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) { 
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {                             
            System.out.println("progress... " + progress);      
            progress_tv.setText(progress);  // Exception...
        }
    });

不幸的是,每当我试图拖动滑块,应用程序崩溃给我一个

unfortunately, whenever i try to drag the thumb , the application crashes giving me an

里面onSeekBarChangeListener ResourceNotFound例外,我设置搜索栏的进展到TextView的。

ResourceNotFound exception inside onSeekBarChangeListener where i set the progress of seekbar to that textview.

我已经尝试都..

TextView progress_tv = (TextView) dialog
                .findViewById(R.id.seekbar_progress_tv2);

TextView progress_tv = (TextView) layoutFromInflater
                    .findViewById(R.id.seekbar_progress_tv2);

但仍然问题仍然存在。

but still problem persist..

任何帮助是AP preciated ..

Any help is appreciated..

推荐答案

的TextView 期望得到的CharSequence ,你传递一个int给它。解决方法之一是 Integer.toString(进度)

TextView expects to get charSequence and you pass an int to it. One way to solve this is Integer.toString(progress)

这篇关于显示搜索栏的进展,一个TextView自定义警告对话框内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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