【发布时间】:2018-04-04 03:19:31
【问题描述】:
嘿,我正在尝试使用持有人模式实现自定义电影列表。目前,我正在成功显示列表。我想在加载唯一活动之前显示一个带有一些消息的进度条。我似乎无法用异步任务将我的头绕在进度条上,我已经遵循了一些示例,但似乎无法理解它们,有人可以建议在哪里插入什么以及插入什么以使其工作。我真的很感激。
这是我唯一的活动
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>
任何帮助将不胜感激。
【问题讨论】:
-
您可以在运行服务获取数据时插入进度条,完成后关闭进度条。
-
您能否展示一个带有异步任务的示例代码,因为我觉得这很难理解?干杯
-
我添加了答案,您将通过它了解如何在代码中使用进度条功能,
标签: android android-asynctask progress-bar