Панель поиска onProgressChanged не работает должным образом (Android)Android

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Панель поиска onProgressChanged не работает должным образом (Android)

Сообщение Anonymous »

Здесь я предоставляю свой класс адаптера, который имеет ползунок панели поиска. Он работает только при нажатии большого пальца на ползунок, но не при перетаскивании.

Код: Выделить всё

package com.welbornindia.app.ui.adapter.device1;

import android.content.Context;
import android.os.Build;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.welbornindia.app.MyApplication;
import com.welbornindia.app.R;
import com.welbornindia.app.config.BaseConfig;
import com.welbornindia.app.config.device1.Config_1;
import com.welbornindia.app.config.device2.Config_2;
import com.welbornindia.app.config.device3.Config_3;
import com.welbornindia.app.domain.DeviceInfo;
import com.welbornindia.app.domain.device1.DeviceBasicProperties_1;
import com.welbornindia.app.domain.device2.DeviceBasicProperties_2;
import com.welbornindia.app.domain.device3.DeviceBasicProperties_3;
import com.welbornindia.app.domain.device4.DeviceBasicProperties_4;
import com.welbornindia.app.ui.view.MyGridView;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

public
/**
* @author       :xuzip
* date          :2022/3/11 10:32
*/
class ScenesItemAdapter_1 extends BaseAdapter {
private OnItemClickListener onItemClickListener;
private Context context;
private List deviceInfos = new ArrayList();

public ScenesItemAdapter_1(Context context, OnItemClickListener onItemClickListener){
this.context = context;
this.onItemClickListener = onItemClickListener;
}

public void setDeviceInfos(List  deviceInfos){
this.deviceInfos = deviceInfos;
this.notifyDataSetChanged();
}

@Override
public int getCount() {
return deviceInfos.size();
}

@Override
public Object getItem(int i) {
return deviceInfos.get(i);
}

@Override
public long getItemId(int i) {
return i;
}

public static class ViewHolder {
ImageView device_img;
TextView device_name;

TextView tv_white_light_brightness;
SeekBar sb_white_light_brightness;
TextView tv_ipl_light_brightness;
SeekBar sb_ipl_light_brightness;

TextView tv_ipl_light_saturation_1;
SeekBar sb_ipl_light_saturation;
TextView tv_white_light_color_temperature;
SeekBar sb_white_light_color_temperature;
TextView tv_ipl_h;
SeekBar sb_color;
TextView tv_group;
ImageView iv_close;

RelativeLayout rel_ipl_brightness;
RelativeLayout rel_temp;

RelativeLayout rel_ipl_saturation;
RelativeLayout rel_ipl_color;

}

@Override
public View getView(int select, View convertView, ViewGroup viewGroup) {
final ViewHolder holder;
if(convertView == null){
convertView = LayoutInflater.from(context).inflate(R.layout.adapter_scene_item, null);
holder = new ViewHolder();

holder.device_img = convertView.findViewById(R.id.device_img);
holder.device_name = convertView.findViewById(R.id.device_name);

holder.tv_white_light_brightness = convertView.findViewById(R.id.tv_white_light_brightness);
holder.sb_white_light_brightness = convertView.findViewById(R.id.sb_white_light_brightness);

holder.tv_white_light_color_temperature = convertView.findViewById(R.id.tv_white_light_color_temperature);
holder.sb_white_light_color_temperature = convertView.findViewById(R.id.sb_white_light_color_temperature);

holder.tv_ipl_light_brightness = convertView.findViewById(R.id.tv_ipl_light_brightness);
holder.sb_ipl_light_brightness = convertView.findViewById(R.id.sb_ipl_light_brightness);

holder.tv_ipl_light_saturation_1 = convertView.findViewById(R.id.tv_ipl_light_saturation_1);
holder.sb_ipl_light_saturation = convertView.findViewById(R.id.sb_ipl_light_saturation);

holder.tv_ipl_h = convertView.findViewById(R.id.tv_ipl_h);
holder.sb_color = convertView.findViewById(R.id.sb_color);

holder.tv_group = convertView.findViewById(R.id.tv_group);
holder.iv_close = convertView.findViewById(R.id.iv_close);

holder.rel_ipl_brightness = convertView.findViewById(R.id.rel_ipl_brightness);
holder.rel_temp = convertView.findViewById(R.id.rel_temp);

holder.rel_ipl_saturation = convertView.findViewById(R.id.rel_ipl_saturation);
holder.rel_ipl_color = convertView.findViewById(R.id.rel_ipl_color);

convertView.setTag(holder);
}else {
holder = (ViewHolder) convertView.getTag();
}

//关键代码
if (viewGroup instanceof MyGridView) {
if (((MyGridView)viewGroup).isOnMeasure) {
return convertView;
}
}

int w_brightness = 100;
int w_temperature = 100;

int i_brightness = 100;

int i_saturation = 100;
int i_color = 100;

int selectGroup = 1;
int selectChannel = 1;
final boolean[] open = {false};

int cct_max = 85;
int cct_min = 25;

holder.sb_white_light_brightness.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean check) {
Log.e("白光 亮度",progress+"   "+ check);
holder.tv_white_light_brightness.setText(progress+"%");
if(check){
if(onItemClickListener!=null){
onItemClickListener.onItemIconClickListener(select,0,progress);
}
}
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}
});

holder.sb_white_light_color_temperature.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean check) {
Log.e("白光 色温",progress+"  "+ check);
holder.tv_white_light_color_temperature.setText(progress+"00K");
if(check){
if(onItemClickListener!=null){
onItemClickListener.onItemIconClickListener(select,1,progress);
}
}
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}
});

holder.sb_ipl_light_brightness.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean check) {
Log.e("彩光 亮度",progress+"  "+ check);
holder.tv_ipl_light_brightness.setText(progress+"%");
if(check){
if(onItemClickListener!=null){
onItemClickListener.onItemIconClickListener(select,2,progress);
}
}
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}
});

holder.sb_ipl_light_saturation.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean check) {
Log.e("彩光 饱和度",progress+"  "+ check);
holder.tv_ipl_light_saturation_1.setText(progress+"%");
if(check){
if(onItemClickListener!=null){
onItemClickListener.onItemIconClickListener(select,3,progress);
}
}
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}
});

holder.sb_color.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean check) {
Log.e("彩光 色彩角度",progress+"  "+ check);
holder.tv_ipl_h.setText("H: "  + progress+"°");
if(check){
if(onItemClickListener!=null){
onItemClickListener.onItemIconClickListener(select,4,progress);
}
}
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}
});

holder.tv_group.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.e("点击 组别", "!");
if(onItemClickListener!=null){
onItemClickListener.onItemIconClickListener(select,5,-1);
}
}
});

holder.iv_close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.e("开关", open[0] +"");
open[0] = !open[0];
holder.iv_close.setImageResource(open[0] ? R.mipmap.open:R.mipmap.close);
if(onItemClickListener!=null){
onItemClickListener.onItemIconClickListener(select,6,  o p e n [ 0 ]   ? 1 : 0 ) ; < b r   / >                                 } < b r   / >                         } < b r   / >                 } ) ; < b r   / > < b r   / > < b r   / > < b r   / >                 D e v i c e I n f o   d e v i c e I n f o   =   d e v i c e I n f o s . g e t ( s e l e c t ) ; < b r   / > < b r   / >                 G l i d e . w i t h ( M y A p p l i c a t i o n . g e t I n s t a n c e ( ) ) < b r   / >                                 . l o a d ( d e v i c e I n f o . g e t D e v i c e _ i c o n ( ) ) < b r   / >                                 . a p p l y ( R e q u e s t O p t i o n s . b i t m a p T r a n s f o r m ( n e w   C i r c l e C r o p ( ) ) ) < b r   / >                                 . i n t o ( h o l d e r . d e v i c e _ i m g ) ; < b r   / > < b r   / >                 h o l d e r . d e v i c e _ n a m e . s etText(deviceInfo.getDevice_finally_name());

switch (deviceInfo.getDeviceType()){
case BaseConfig.DEVICE_1:
DeviceBasicProperties_1 deviceBasicProperties1 = deviceInfo.getObject();
w_brightness = deviceBasicProperties1.getWhite_light_brightness();
w_temperature = deviceBasicProperties1.getWhite_light_temperature();
i_brightness = deviceBasicProperties1.getIpl_light_brightness();
i_saturation = deviceBasicProperties1.getIpl_light_saturation();
i_color = deviceBasicProperties1.getIpl_light_h();
open[0] = deviceBasicProperties1.isMain_switch();

selectGroup =  deviceBasicProperties1.getGroup();
selectChannel = deviceBasicProperties1.getChannel();

cct_max = Config_1.CCT_MAX;
cct_min = Config_1.CCT_MIN;

holder.rel_temp.setVisibility(View.VISIBLE);

holder.rel_ipl_brightness.setVisibility(View.VISIBLE);
holder.rel_ipl_saturation.setVisibility(View.VISIBLE);
holder.rel_ipl_color.setVisibility(View.VISIBLE);
break;
case BaseConfig.DEVICE_2:
DeviceBasicProperties_2 deviceBasicProperties2 = deviceInfo.getObject();
w_brightness = deviceBasicProperties2.getWhite_light_brightness();
w_temperature = deviceBasicProperties2.getWhite_light_temperature();
i_brightness = deviceBasicProperties2.getIpl_light_brightness();
i_saturation = deviceBasicProperties2.getIpl_light_saturation();
i_color = deviceBasicProperties2.getIpl_light_h();
open[0] = deviceBasicProperties2.isMain_switch();

selectGroup =  deviceBasicProperties2.getGroup();
selectChannel = deviceBasicProperties2.getChannel();

cct_max = Config_2.CCT_MAX;
cct_min = Config_2.CCT_MIN;

holder.rel_temp.setVisibility(View.VISIBLE);

holder.rel_ipl_brightness.setVisibility(View.GONE);
holder.rel_ipl_saturation.setVisibility(View.GONE);
holder.rel_ipl_color.setVisibility(View.GONE);
break;
case BaseConfig.DEVICE_3:
DeviceBasicProperties_3 deviceBasicProperties3 = deviceInfo.getObject();
w_brightness = deviceBasicProperties3.getWhite_light_brightness();
w_temperature = deviceBasicProperties3.getWhite_light_temperature();
i_brightness = deviceBasicProperties3.getIpl_light_brightness();
i_saturation = deviceBasicProperties3.getIpl_light_saturation();
i_color = deviceBasicProperties3.getIpl_light_h();
open[0] = deviceBasicProperties3.isMain_switch();

selectGroup =  deviceBasicProperties3.getGroup();
selectChannel = deviceBasicProperties3.getChannel();

cct_max = Config_3.CCT_MAX;
cct_min = Config_3.CCT_MIN;

holder.rel_temp.setVisibility(View.VISIBLE);

holder.rel_ipl_brightness.setVisibility(View.GONE);
holder.rel_ipl_saturation.setVisibility(View.GONE);
holder.rel_ipl_color.setVisibility(View.GONE);
break;
case BaseConfig.DEVICE_4:
DeviceBasicProperties_4 deviceBasicProperties4 = deviceInfo.getObject();
w_brightness = deviceBasicProperties4.getWhite_light_brightness();
w_temperature = deviceBasicProperties4.getWhite_light_temperature();
i_brightness = deviceBasicProperties4.getIpl_light_brightness();
i_saturation = deviceBasicProperties4.getIpl_light_saturation();
i_color = deviceBasicProperties4.getIpl_light_h();
open[0] = deviceBasicProperties4.isMain_switch();

selectGroup =  deviceBasicProperties4.getGroup();
selectChannel = deviceBasicProperties4.getChannel();

holder.rel_temp.setVisibility(View.VISIBLE);

holder.rel_ipl_brightness.setVisibility(View.GONE);
holder.rel_ipl_saturation.setVisibility(View.GONE);
holder.rel_ipl_color.setVisibility(View.GONE);
break;
}

holder.sb_white_light_brightness.setProgress(w_brightness);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)  {
holder.sb_white_light_color_temperature.setMin(cct_min);
}else {
setProgressMin(holder.sb_white_light_color_temperature,cct_min);
}
holder.sb_white_light_color_temperature.setMax(cct_max);

holder.sb_white_light_color_temperature.setProgress(w_temperature);

holder.sb_ipl_light_brightness.setProgress(i_brightness);

holder.sb_ipl_light_saturation.setProgress(i_saturation);

holder.sb_color.setProgress(i_color);

holder.tv_group.setText(" Grp:"+BaseConfig.GROUP_NUMBER[selectGroup]+" Ch:"+BaseConfig.CHANNEL_NUMBER[selectChannel]);

holder.iv_close.setImageResource(open[0] ? R.mipmap.open:R.mipmap.close);

return convertView;
}

public abstract static class OnItemClickListener{
public abstract void onItemIconClickListener(int selected,int viewId,int value);
}

public void setProgressMin(ProgressBar progressBar,int min){
// 检查setMin方法是否存在
Method setMinMethod;
try {
setMinMethod = progressBar.getClass().getMethod("setMin", int.class);
} catch (NoSuchMethodException e) {
Log.w("ProgressBarCompat", "setMin method not found, using default behavior");
// 如果找不到setMin方法,可以在这里设置默认行为,比如min = 0
return;
}

try {
setMinMethod.invoke(progressBar, min);
} catch (IllegalAccessException | InvocationTargetException e) {
Log.e("ProgressBarCompat", "Failed to set progress bar minimum value", e);
}
}
}

Пожалуйста, помогите мне.
Я здесь использую держатель представления, в котором мы используем Seekbar.setOnSeekBarChangeListener, только когда мы касаемся, тогда он работает но onProgressChange не работает с перетаскиванием.
Пожалуйста, скажите мне, в чем я ошибаюсь.
onProgressChanged вызывается только при нажатии, а не при перетаскивании .
Ползунок панели поиска не работает при перетаскивании, работает только при нажатии.

Подробнее здесь: https://stackoverflow.com/questions/791 ... ly-android
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»