각기 SeekBar가 들어있는 ListView (또는 GridView, 화면 크기에 따라 다름) 사용자 지정 항목이 있습니다. OnSeekBarChangeListener를 설정 중이며 문제는 버튼을 놓은 후 또는 엄지 위치를 변경 한 후에 onStartTrackingTouch가 실행된다는 것입니다 (프레스 이후이어야 함). 나는 ListView, 또는 ListView의 행이 이벤트를 도용하고 있다고 생각했지만 많은 다른 솔루션을 시도했지만 아무런 효과가 없었다.ListView의 SeekBar가 onStartTrackingTouch에 올바르게 응답하지 않습니다.
onStartTrackingTouch도 사용하고 싶지 않습니다. 이 작업이 필요한 이유는 사용자가 엄지 손가락을 누를 때 상태가 바뀌므로 (사용자가 엄지 손가락을 드래그하기 시작했음을 알기 때문입니다). 이제 엄지 손가락은 위치가 바뀌었을 때만 상태를 변경합니다.
MainActivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView list = (ListView) findViewById(R.id.seekbarList);
list.setAdapter(new Adapter());
SeekBar sb = (SeekBar) findViewById(R.id.seekBarOutsideTheList);
sb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
((TextView) findViewById(R.id.outsideListLbl))
.setText("onStop");
Log.d("seekBarOutsideTheList", "onStop");
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
((TextView) findViewById(R.id.outsideListLbl))
.setText("onStart");
Log.d("seekBarOutsideTheList", "onStart");
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
((TextView) findViewById(R.id.outsideListLbl))
.setText("onChange");
Log.d("seekBarOutsideTheList", "onChange");
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public class Adapter extends BaseAdapter {
LayoutInflater layoutInflter;
public Adapter() {
layoutInflter = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
class ViewHolder {
TextView label;
SeekBar seek;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = layoutInflter.inflate(R.layout.list_row, null);
ViewHolder viewHolder = new ViewHolder();
viewHolder.label = (TextView) convertView
.findViewById(R.id.insideListLbl);
viewHolder.seek = (SeekBar) convertView
.findViewById(R.id.seekbarInLIst);
convertView.setTag(viewHolder);
}
ViewHolder viewHolder = (ViewHolder) convertView.getTag();
viewHolder.seek
.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
((TextView) findViewById(R.id.insideListLbl))
.setText("onStop");
Log.d("seekBarInsideTheList", "onStop");
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
((TextView) findViewById(R.id.insideListLbl))
.setText("onStart");
Log.d("seekBarInsideTheList", "onStart");
}
@Override
public void onProgressChanged(SeekBar seekBar,
int progress, boolean fromUser) {
((TextView) findViewById(R.id.insideListLbl))
.setText("onChange");
Log.d("seekBarInsideTheList", "onChange");
}
});
return convertView;
}
@Override
public int getCount() {
return 1;
}
@Override
public Integer getItem(int arg0) {
return arg0;
}
}
}
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SeekBar outside the list" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<SeekBar
android:id="@+id/seekBarOutsideTheList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="@+id/outsideListLbl"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
<ListView
android:id="@+id/seekbarList"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
list_row.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="SeekBar inside the list" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<SeekBar
android:id="@+id/seekbarInLIst"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="@+id/insideListLbl"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
답장을 보내 주셔서 감사합니다.하지만 말씀대로 : "onStartTrackingTouch는 엄지 손가락 변경에 호출됩니다." 이건 내가 원하는 행동이 아니야. ListView가 아닌 단일 SeekBar를 사용하면 엄지 손가락을 눌렀을 때 StartTrackingTouch가 실행됩니다.목록에서 원하는이 기본 동작 및 왜 다르게 동작하는지 알 수 없습니다. –