1

您好,我想知道如何在findViewById(int id)扩展的类中使用以下方法,该类Preference定义了一个调用setProgress(int progress)该方法的方法,该方法使用该方法findViewById,以便在另一个扩展的类中PreferenceActivity使用该方法setProgress(int progress)。因此,由于该方法findViewById是在类中定义的,android.view.View我想如何使用该方法。

4

2 回答 2

0

您必须将特定视图或活动传递给函数,或者如果 setProgress 函数不是静态的,则以某种方式将视图或活动存储在类内的变量中。

于 2012-01-01T07:20:04.547 回答
0

我在这个网站上找到了答案:http: //www.codeproject.com/Articles/163541/SeekBar-Preference

你可以使用

LayoutInflater inflater = (LayoutInflater) setContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.dialog_slider, null);

然后您可以使用 id 查找视图

mSeekBar = (SeekBar) view.findViewById(R.id.seek_bar);
于 2012-07-24T16:32:55.783 回答