开发者

How to get progress values from SeekBar created in ListAdapter?

开发者 https://www.devze.com 2023-04-09 07:57 出处:网络
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'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 cl开发者_如何学编程ass. 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 ;) )!


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号