こんにちは私はホルダーパターンを使用してカスタムムービーリストを実装しようとしています。現在、リストを正常に表示しています。唯一のアクティビティがロードされる前に、いくつかのメッセージとともにプログレスバーを表示したい。私は非同期タスクと進行状況バーの周りに私の頭を包み込むように見えることができないと私はいくつかの例に従っているが、それらを理解するように見えることができない、誰かがそれを動作させるために挿入するためにどこにアドバイスしてください。私は本当にそれを感謝します。ここでカスタムリストのプログレスバー
が
public class MovieRatingsActivity extends ListActivity
{
private ArrayList<Movie> movies = new ArrayList<Movie>();
private LayoutInflater mInflater;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initializeUI();
}
private void initializeUI()
{
mInflater = (LayoutInflater)
this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
InputStream inputStream = getResources().openRawResource( R.raw.ratings);
movies = Movie.loadFromFile(inputStream);
setListAdapter(new RowIconAdapter(this, R.layout.listrow, R.id.row_label, movies));
}
//declare a static holder class
public static class ViewHolder{
ImageView icon;
TextView movieText,votesText;
}
/** Custom row adatper -- that displays an icon next to the movie name */
class RowIconAdapter extends ArrayAdapter<Movie>
{
private ArrayList<Movie> movies;
public RowIconAdapter(Context c, int rowResourceId, int textViewResourceId,
ArrayList<Movie> items)
{
super(c, rowResourceId, textViewResourceId, items);
movies = items;
}
public View getView(int pos, View convertView, ViewGroup parent)
{
//declare a holder object
ViewHolder holder;
Movie currMovie = movies.get(pos);
//nly inflate view once and get all the views once
if (convertView == null)
{
convertView = mInflater.inflate(R.layout.listrow, parent, false);
holder = new ViewHolder();
holder.icon = (ImageView) convertView.findViewById(R.id.row_icon);
holder.movieText = (TextView) convertView.findViewById(R.id.row_label);
holder.votesText= (TextView) convertView.findViewById(R.id.row_subtext);
//set the holder class
convertView.setTag(holder);
}
else{
//get all the views once done
holder = (ViewHolder) convertView.getTag();
}
//set all the values in the list
holder.movieText.setText(currMovie.getName());
String votesStr = currMovie.getVotes()+" votes";
holder.votesText.setText(votesStr);
Bitmap movieIcon = getMovieIcon(currMovie.getName(), currMovie.getRating());
holder.icon.setImageBitmap(movieIcon);
return convertView;
}
}
私の唯一のアクティビティである私のレイアウトファイル:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@android:id/list"
android:layout_height="fill_parent"
android:layout_width="match_parent" />
</LinearLayout>
任意の助けいただければ幸いです。
サービスを実行してデータを取得するときに進行状況バーを挿入し、完了時に進行状況バーを閉じることができます。 – Umair
非同期タスクのサンプルコードを理解しにくいものとして表示できますか? Cheers – Sam
コード内のプログレスバー機能の使い方を知るための答えを追加します。 – Umair