Привет, ребята, добавили весь код, который я мог бы ниже, в отношении моей проблемы. Обратите внимание, что как индикатор выполнения, так и текстовое представление НЕ ОБНОВЛЯЮТСЯ через асинтез. Текстовое изображение может быть отредактировано в методе getview, но не в панели прогресса, поскольку, когда я пытаюсь установить значение 40, он не обновляет ui как 40.UI Objects & ProgressBar - не обновляет AsyncTask
Код Ниже комментируется, пожалуйста, прочитайте комментарии! Я пробовал много разных способов, но я все еще застрял здесь
И textview, и ProgressBar не обновляют с помощью (onprogressupdated) asyncTask на данный момент.
Вот ссылка на официальный андроида документ в качестве кода сравнения: http://developer.android.com/reference/android/os/AsyncTask.html
Вот еще StackOverflow вопрос, который я посмотрел на: Android Async Task Progress Bar onProgressUpdate
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
if (!(data.get(position) instanceof TemporarySongInfomation)) {
SongViewHolder holder;
if(view == null) {
view = inflater.inflate(R.layout.music_list_format, null);
holder = new SongViewHolder();
holder.timesplayed = (TextView) view.findViewById(R.id.textView7);
holder.artist = (TextView) view.findViewById(R.id.textView6);
holder.title = (TextView) view.findViewById(R.id.textView5);
holder.imagebutton = (ImageButton) view.findViewById(R.id.playbutton);
holder.source = (TextView) view.findViewById(R.id.textView8);
} else holder = (SongViewHolder)view.getTag();
tempValue = (SongInfomation) data.get(position);
String songName = tempValue.getName();
holder.imagebutton.setBackgroundResource(R.drawable.playbutton1);
holder.source.setText(tempValue.getVideoid());
holder.title.setText(songName.length() > 45 ? songName.substring(0, 38) + "..." : songName);
holder.timesplayed.setText("" + tempValue.getTimesplayed());
holder.artist.setText(tempValue.getArtist());
swipeDetector = new SwipeDetector();
view.setOnClickListener(new SongListOnItemClickListener(position));
view.setOnTouchListener(swipeDetector);
holder.imagebutton.setOnClickListener(new OnPlayButtonClickListener(position));
} else {
TemporarySongViewHolder holder = new TemporarySongViewHolder();
if(view == null) {
view = inflater.inflate(R.layout.music_list_process_format, null);
holder.artist = (TextView) view.findViewById(R.id.artisttemp);
holder.bar = (ProgressBar) view.findViewById(R.id.progressBar2);
holder.textpercent = (TextView) view.findViewById(R.id.textView9);
holder.title = (TextView) view.findViewById(R.id.titletemp);
holder.source = (TextView) view.findViewById(R.id.sourcetemp);
} else holder = (TemporarySongViewHolder) view.getTag();
tempValue1 = (TemporarySongInfomation) data.get(position);
String songName = tempValue1.getName();
holder.source.setText(tempValue1.getVideoid());
holder.title.setText(songName.length() > 45 ? songName.substring(0, 38) + "..." : songName);
holder.artist.setText(tempValue1.getArtist());
holder.textpercent.setText("Initializing");
new UpdateProgressBar(holder.bar, tempValue1, holder.textpercent).execute();
}
return view;
}
class UpdateProgressBar extends AsyncTask<Void, Integer, Void> {
TemporarySongInfomation songinfo;
ProgressBar progress;
TextView textpercent;
UpdateProgressBar(ProgressBar bar, TemporarySongInfomation tp, TextView percent) {
progress = bar;
songinfo = tp;
textpercent = percent;
}
@Override
protected Void doInBackground(Void... params) {
while (!songinfo.isCompleted()) {
publishProgress((int) songinfo.getProgress());
try {
Thread.sleep(500);
} catch (Exception e) {
}
}
return null;
}
@Override
protected void onProgressUpdate(Integer... values) {
System.out.println("progress: "+values[0]);
progress.setProgress(values[0]);
textpercent.setText("Current Progress: "+values[0] + "%");
}
}
XML при необходимости также откомментировал пожалуйста, прочитайте:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/titletemp"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:textSize="16dp"
android:textColor="#ffffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/artisttemp"
android:layout_below="@+id/titletemp"
android:layout_alignParentStart="true"
android:textColor="#ffffffff"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/sourcetemp"
android:layout_alignTop="@+id/artisttemp"
android:layout_centerHorizontal="true"
android:textColor="#ffffffff"/>
<ProgressBar
android:layout_width="match_parent"
android:layout_height="10dp"
android:indeterminate="false"
android:id="@+id/progressBar2"
android:layout_below="@+id/sourcetemp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/textView9"
android:textColor="#ffffffff"
android:layout_centerHorizontal="true"
android:layout_below="@+id/progressBar2" />
Как просили:
class SongViewHolder {
TextView title, artist, timesplayed, source;
ImageButton imagebutton;
}
class TemporarySongViewHolder {
TextView title, artist, source, textpercent;
ProgressBar bar;
}
является его вводом в то время как цикл ? –
да, но в соответствии с документами android docs publishProgress может произойти внутри цикла, например, если вы посмотрите, что они используют forloop –
нет, я спрашиваю вас, когда вы запустите его внутри? –