Wie kann ich den ListView-Elementwert bei Seekbar-Fortschrittsänderungen ändern?ListView-Element in Suchleiste ändern Wertänderung
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<SeekBar
android:id="@+id/seekValue"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:max="100" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="10dp">
<ListView
android:id="@+id/listSelector"
android:layout_width="fill_parent"
android:layout_height="fill_parent"></ListView>
</LinearLayout>
</LinearLayout>
und Listview-Element ist:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/layoutSelector"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="@android:color/darker_gray">
<TextView
android:id="@+id/txtItemName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/txtValueChanges"
android:padding="5dp"
android:text="Item Name"
android:textAppearance="?android:textAppearanceLarge"
android:textStyle="bold" />
<TextView
android:id="@+id/txtValueChanges"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:padding="5dp"
android:visibility="gone"
android:text="0"
android:textAppearance="?android:textAppearanceMedium"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
Nun ist dies aussieht meine mailActivity Klasse wie:
public class ListActivitys extends Activity {
ArrayList listItemName;
public static ListView listSelector;
SeekBar seekValue;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
listItemName = new ArrayList();
for (int i = 0; i < 50; i++) {
listItemName.add("Item : " + (i + 1));
}
seekValue = (SeekBar) findViewById(R.id.seekValue);
listSelector = (ListView) findViewById(R.id.listSelector);
listSelector.setAdapter(new AdapterList(ListActivitys.this, listItemName,seekValue));
}
}
und schließlich ist mein benutzerdefinierter Adapter:
public class AdapterList extends BaseAdapter {
Context mcContext;
ArrayList listItems, TempListItems;
int selectedPos = 0;
SeekBar seekValue;
public AdapterList(Context listActivitys, ArrayList listItemName, SeekBar seek) {
listItems = listItemName;
mcContext = listActivitys;
seekValue = seek;
createATemList(listItemName.size());
}
private void createATemList(int size) {
TempListItems = new ArrayList();
for (int i=0; i<size; i++){
TempListItems.add("0");
}
}
@Override
public int getCount() {
return listItems.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
LayoutInflater mInflater = (LayoutInflater) mcContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.adapter_list_item, null);
holder = new ViewHolder();
holder.txtItemName = (TextView) convertView.findViewById(R.id.txtItemName);
holder.txtValueChanges = (TextView) convertView.findViewById(R.id.txtValueChanges);
holder.layoutSelector = (RelativeLayout) convertView.findViewById(R.id.layoutSelector);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
if (selectedPos == position) {
holder.layoutSelector.setBackgroundColor(mcContext.getResources().getColor(R.color.colorAccent));
} else {
holder.layoutSelector.setBackgroundColor(mcContext.getResources().getColor(R.color.transparent));
}
if (!TempListItems.get(selectedPos).equals("0")){
holder.txtValueChanges.setVisibility(View.VISIBLE);
}else{
holder.txtValueChanges.setVisibility(View.GONE);
}
holder.txtItemName.setText(listItems.get(position).toString());
holder.layoutSelector.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
selectedPos = position;
notifyDataSetChanged();
}
});
seekValue.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
/*View view = (View) seekBar.getParent();
if(view != null){
TextView tvProgress = (TextView)view.findViewById(R.id.txtValueChanges);
tvProgress.setVisibility(View.VISIBLE);
tvProgress.setText(progress + "%");
}*/
updateView(selectedPos, progress);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
return convertView;
}
private void updateView(int selectedPos, int progress) {
View v = ListActivitys.listSelector.getChildAt(selectedPos -
ListActivitys.listSelector.getFirstVisiblePosition());
if (v == null)
return;
TextView txtValueChanges = (TextView) v.findViewById(R.id.txtValueChanges);
TempListItems.set(selectedPos,progress+"");
if (!TempListItems.get(selectedPos).equals("0")){
System.out.println("=== Progress : " + progress);
txtValueChanges.setText(TempListItems.get(selectedPos)+"");
notifyDataSetChanged();
}
}
private class ViewHolder {
TextView txtValueChanges;
TextView txtItemName;
RelativeLayout layoutSelector;
}
}
ist Es ist möglich, den Wert von ListView zu ändern Element, wenn der Wert der Suchleiste geändert wird. Wenn ja, wie? Bitte hilf mir.
Danke.
Wenn Suchleiste ändern, welches Element in 'ListView' möchten Sie ändern? –
Ich möchte das ausgewählte Element von ListView ändern, deshalb verwalte ich die ausgewählte Position bei Klick auf layoutSelector und veröffentliche den Wert der Suchleiste in txtValueChanges Element von ListView. –
ja möglich mit einer Flagge. Wenn sich das Flag ändert (beim Ändern der Suchleiste), benachrichtigen Sie den Adapter. Ändern Sie die UI zur Auswahl basierend auf diesem Flag in getView() –