如何从ListAdapter中创建的SeekBar获取进度值?

发布于 2024-12-07 10:15:02 字数 1350 浏览 2 评论 0原文

我目前正在开发我的第一个 Android 应用程序,这是我的第一段 Java 代码,我想我已经走了很远了,但现在我陷入了以下主题:

我有一个 ListActivity,它显示来自自定义的 rowViews从 json 对象生成的 ListAdapter。一般来说,有 3 种类型的对象:

房间,既没有按钮也没有滑块。这些在我的 ListActivity 中是这样处理的:

@Override
protected void onListItemClick (ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    Log.d(TAG,"Area" + l.getItemAtPosition(position).toString() + "clicked");
    handleControlItemActions((JSONObject)l.getItemAtPosition(position));
}

可切换设备,有一个要打开和关闭的切换按钮,处理方式如下(onObjectSwitch 在 xml 中定义为按钮的 onClick 操作):

    public void onObjectSwitch (final View view) {
     Log.d(TAG,"Object" + view.getId()+ " clicked");
     handleControlItemActions((JSONObject)l.getItemAtPosition(position));
}   

可调光设备,有一个 SeekBar,以及这是我的问题: 我知道“onSeekBarChangeListener”,但我不知道如何将其设置为 Activity 类中 rowViews 内的 SeekBars。 这些栏是由 Listadapter 创建的,如下所示:

    case 1:
    textView.setText((String)controlItem.get("name") + " " +(String)controlItem.getString("actual")+"°C");
    slider.setVisibility(View.VISIBLE);
    slider.setId(position);
    slider.setProgress(controlItem.getInt("setPoint"));
    slider.setMax(controlItem.getInt("max"));
    break;

谁能告诉我如何处理这些滑块?或者我什至没有走上管理这些小部件的正确轨道?

预先感谢大家(并对我的拼写感到抱歉;))!

I'm curently working on my first Android app, which is my first pice of java code at all, i think I got pretty far already but now I'm stuck on the following topic:

I have a ListActivity which shows rowViews from a custom ListAdapter generated from json objects. Generaly there are 3 types of objects:

Rooms, which neither have a button nor a slider. Those are handled like this in my ListActivity:

@Override
protected void onListItemClick (ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    Log.d(TAG,"Area" + l.getItemAtPosition(position).toString() + "clicked");
    handleControlItemActions((JSONObject)l.getItemAtPosition(position));
}

Switchable devices, which have a toggle button to be switched on and off are handled like this (onObjectSwitch is defined in xml as onClick action for the button):

    public void onObjectSwitch (final View view) {
     Log.d(TAG,"Object" + view.getId()+ " clicked");
     handleControlItemActions((JSONObject)l.getItemAtPosition(position));
}   

Dimmable devices, which have a SeekBar, and here is my problem:
I know the "onSeekBarChangeListener", but I have no clue how I can set it to the SeekBars which are inside the rowViews from my Activity class.
The bars are created by the Listadapter like this:

    case 1:
    textView.setText((String)controlItem.get("name") + " " +(String)controlItem.getString("actual")+"°C");
    slider.setVisibility(View.VISIBLE);
    slider.setId(position);
    slider.setProgress(controlItem.getInt("setPoint"));
    slider.setMax(controlItem.getInt("max"));
    break;

Can anyone tell me how to handle those sliders? Or am I not even on the right track to manage those widgets?

Thanks in advance to everyone (and sorry for my spelling ;) )!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还给你自由 2024-12-14 10:15:02

好的,明白了:
只需将 listadapter 定义为 listactivity 内部的子类,现在您就可以引用这些方法,而无需将它们标记为“静态”。

Okay got it:
just define the listadapter as a subclass inside of the listactivity, now you're able to reffere to the methods without flagging them "static".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文