在滚动 gridview 之前的图像替换为下面的图像并再次向上滚动其再次加载后出现一个问题应用程序/详细信息?id=com.vaibhavtech.mbmovies
public class NewMovie extends Activity {
private GridView lv;
private Vibrator vibrator;
private ArrayList<DataDemo> mDemoDataAl;
private ProgressDialog progressDialog;
private String mStringURL = "";
private ImageLoader mImageLoader = null;
protected static final int SHOW_PROGRESS_DIALOG = 0;
protected static final int STOP_PROGRESS_DIALOG = 1;
protected static final int NETWORK_FAILURE = 2;
protected static final int PROBLEM_IN_CONNECTING_SERVER = 3;
protected static final int SET_ADAPTER = 4;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.new_movie);
setProgressBarIndeterminateVisibility(true);
setProgressBarIndeterminateVisibility(false);
super.onCreate(savedInstanceState);
mDemoDataAl = new ArrayList<DataDemo>();
mImageLoader = ImageLoader.getInstance();
vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
lv = (GridView) findViewById(R.id.grid_view);
mStringURL = "http://vaibhavtech.com/work/android/movie_list.php?category="
+ MainActivity.movie_Category + "&sub_category=new";
Log.d("The Url is ", " URL : " + mStringURL);
lv.setOnScrollListener(new EndlessScrollListener());
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// // TODO Auto-generated method stub
vibrator.vibrate(40);
MainActivity.movie_Id = ((TextView) arg1
.findViewById(R.id.tv_girdview_content_id)).getText()
.toString();
startActivity(new Intent(NewMovie.this, MovieDescription.class));
}
});
new GetDemoData().execute();
}
private class GetDemoData extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
try {
JSONObject json = JSONfunctions.getJSONfromURL(mStringURL,
NewMovie.this);
if (json != null) {
JSONArray MoviesArray = json.getJSONArray("Demo");
for (int i = 0; i < MoviesArray.length(); i++) {
DataDemo mDemoData = new DataDemo();
mDemoData.setmDemoId(MoviesArray.getJSONObject(i)
.getString("id"));
mDemoData.setmDemoTitle(MoviesArray.getJSONObject(i)
.getString("title"));
mDemoData.setmDemoYear(MoviesArray.getJSONObject(i)
.getString("year"));
mDemoData.setmDemoDuration(MoviesArray.getJSONObject(i)
.getString("duration"));
mDemoData.setmDemoPoster(MoviesArray.getJSONObject(i)
.getString("poster"));
mDemoDataAl.add(mDemoData);
}
} else {
mHandler.sendEmptyMessage(PROBLEM_IN_CONNECTING_SERVER);
}
} catch (Exception e) {
Log.d("Exceptions",
" The Xception messages are " + e.getMessage());
}
return null;
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
mHandler.sendEmptyMessage(SHOW_PROGRESS_DIALOG);
mDemoDataAl.clear();
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
mHandler.sendEmptyMessage(SET_ADAPTER);
mHandler.sendEmptyMessage(STOP_PROGRESS_DIALOG);
}
}
public class NewMoviesAdapter extends BaseAdapter {
private LayoutInflater mInflater = null;
public NewMoviesAdapter() {
mInflater = LayoutInflater.from(NewMovie.this);
}
public int getCount() {
return mDemoDataAl.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.grid_view_content,
null);
holder = new ViewHolder();
holder.txtMovieId = (TextView) convertView
.findViewById(R.id.tv_girdview_content_id);
holder.txtMovieDuration = (TextView) convertView
.findViewById(R.id.tv_girdview_content_listner);
holder.txtMovieName = (TextView) convertView
.findViewById(R.id.tv_girdview_content_name);
holder.txtMovieYear = (TextView) convertView
.findViewById(R.id.tv_girdview_content_like);
holder.imgMovie = (ImageView) convertView
.findViewById(R.id.iv_girdview_content_image);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
try {
holder.txtMovieId.setText(Utils
.asUpperCaseFirstChar(mDemoDataAl.get(position)
.getmDemoId()));
holder.txtMovieDuration.setText(mDemoDataAl.get(position)
.getmDemoDuration());
holder.txtMovieName.setText(Utils
.asUpperCaseFirstChar(mDemoDataAl.get(position)
.getmDemoTitle()));
holder.txtMovieYear.setText(mDemoDataAl.get(position)
.getmDemoYear());
mImageLoader.displayImage(
"http://vaibhavtech.com/work/android/admin/upload/"
+ mDemoDataAl.get(position).getmDemoPoster(),
holder.imgMovie);
} catch (Exception e) {
}
return convertView;
}
class ViewHolder {
public TextView txtMovieId;
public TextView txtMovieDuration;
public TextView txtMovieName;
public TextView txtMovieYear;
public ImageView imgMovie;
}
}
public class EndlessScrollListener implements OnScrollListener {
private int visibleThreshold = 5;
private int currentPage = 0;
private int previousTotal = 5;
private boolean loading = true;
public EndlessScrollListener() {
}
public EndlessScrollListener(int visibleThreshold) {
this.visibleThreshold = visibleThreshold;
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
if (loading) {
if (totalItemCount > previousTotal) {
loading = false;
previousTotal = totalItemCount;
currentPage++;
}
}
if (!loading
&& (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold)) {
// I load the next page of gigs using a background task,
// but you can call any function here.
// new do.execute(currentPage + 1);
loading = true;
}
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
}
Handler mHandler = new Handler() {
public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case SHOW_PROGRESS_DIALOG:
if (progressDialog == null) {
progressDialog = Utils.createProgressDialog(NewMovie.this);
progressDialog.setMessage("Loding...");
progressDialog.show();
} else {
progressDialog.show();
}
mHandler.removeMessages(SHOW_PROGRESS_DIALOG);
break;
case STOP_PROGRESS_DIALOG:
progressDialog.dismiss();
mHandler.removeMessages(STOP_PROGRESS_DIALOG);
break;
case NETWORK_FAILURE:
Utils.displayToast(NewMovie.this,
Constant.NO_NETWORK_CONNECTION);
mHandler.removeMessages(NETWORK_FAILURE);
break;
case PROBLEM_IN_CONNECTING_SERVER:
Utils.displayToast(NewMovie.this,
Constant.PROBLEM_IN_CONNECTING_SERVER);
mHandler.removeMessages(PROBLEM_IN_CONNECTING_SERVER);
break;
case SET_ADAPTER:
lv.setAdapter(new NewMoviesAdapter());
mHandler.removeMessages(SET_ADAPTER);
break;
default:
break;
}
};
};
}
newmovie.xml* * ** * ** * ** * ** * ** * ** * ** * ***
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="10dp"
android:orientation="vertical" >
<GridView
android:id="@+id/grid_view"
android:layout_width="fill_parent"
android:layout_height="377dp"
android:horizontalSpacing="10dp"
android:numColumns="2"
android:verticalSpacing="10dp" >
</GridView>
</LinearLayout>
主要活动.java
public class MyApplication extends Application {
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
getApplicationContext())
.threadPriority(Thread.NORM_PRIORITY - 2)
.denyCacheImageMultipleSizesInMemory()
.discCacheFileNameGenerator(new Md5FileNameGenerator())
.tasksProcessingOrder(QueueProcessingType.LIFO)
.writeDebugLogs() // Remove for release app
.build();
// Initialize ImageLoader with configuration.
ImageLoader.getInstance().init(config);
}