简体   繁体   English

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

[英]How to get progress values from SeekBar created in ListAdapter?

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: 我目前正在开发我的第一个Android应用程序,这是我第一次使用Java代码,我想我已经走了很多,但是现在我陷入了以下话题:

I have a ListActivity which shows rowViews from a custom ListAdapter generated from json objects. 我有一个ListActivity,它显示了从json对象生成的自定义ListAdapter的rowViews。 Generaly there are 3 types of objects: 通常,有3种类型的对象:

Rooms, which neither have a button nor a slider. 房间,既没有按钮也没有滑块。 Those are handled like this in my ListActivity: 这些在我的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): 具有可打开和关闭的切换按钮的可切换设备的处理方式如下(onObjectSwitch在xml中定义为按钮的onClick动作):

    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. 有一个SeekBar的可调光设备,这是我的问题:我知道“ onSeekBarChangeListener”,但是我不知道如何将其设置为来自Activity类的rowViews内的SeekBars。 The bars are created by the Listadapter like this: 这些条由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;

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 ;) )! 在此先感谢大家(对我的拼写感到抱歉;))!

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM