在我的应用程序中,我有一个listview,它根据搜索关键字加载数据,现在我想在按钮点击时清除加载的数据。
@Override
protected void onPreExecute() {
SearchUtils searchUtils = null;
List<Place> searchResult = null;
String searchType = null;
Log.d(TAG, "onPreExecute start=");
// show your dialog
super.onPreExecute();
Log.d(TAG, "LoadMenuSearch isOldDataToLoad : " + isOldDataToLoad);
if(!this.isOldDataToLoad){
this.dialog.setCanceledOnTouchOutside(false);
this.dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
this.dialog.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface arg0) {
}
});
Button morerecords = (Button) activity.findViewById(R.id.morerecords);
morerecords.setVisibility(View.GONE);
morerecords.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "Do Nothing........................");
}
});
//morerecords.setVisibility(View.VISIBLE);
final Button closesearch = (Button) activity.findViewById(R.id.closesearch);
closesearch.setVisibility(View.VISIBLE);
closesearch.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ListView menuSearchListView = (ListView) activity
.findViewById(R.id.menusearchlist);
searchAdapter.clear();
searchAdapter.notifyDataSetChanged();
closesearch.setVisibility(View.GONE);
}
});
这里在preexecute我有一个按钮,现在当我点击按钮时,加载的数据应该清除,listview应该刷新。
我的搜索适配器
public SearchAdapter(Activity activity, int viewResourceId, int renderer,
double latitute, double longitute, String menuId,
ArrayList<Neighborhood> nhdDetails,
ArrayList<AttractionData> items, boolean isAddressBook,
boolean isRecommended) {
super(activity, viewResourceId, items);
streetView = new StreetViewUtils(activity);
streetView.loadHtml();
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater inflater = (LayoutInflater) (getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE));
view = inflater.inflate(renderer, null);
}
attractionData = items.get(position);
Log.d(TAG, "attractionData " + attractionData + " for position "
+ position);
TextView textName = (TextView) view.findViewById(R.id.textName);
TextView textAddress = (TextView) view.findViewById(R.id.textAddress);
TextView textPhone = (TextView) view.findViewById(R.id.textPhone);
addFavorite = (ImageView) view.findViewById(R.id.pinsave);
LinearLayout itemlayer = (LinearLayout) view
.findViewById(R.id.itemlayer);
itemlayer.setTag(attractionData);
textName.setText(attractionData.getfName());
if (!isRecommended) {
TextView mapidDisplay = (TextView) view.findViewById(R.id.mapid);
mapidDisplay.setTextSize(Constants.defaultFontSize + 2);
if (isAddressBook) {
mapidDisplay.setBackgroundColor(Color.YELLOW);
mapidDisplay.setTextColor(Color.BLACK);
} else {
mapidDisplay.setBackgroundColor(Color.RED);
mapidDisplay.setTextColor(Color.WHITE);
}
mapidDisplay.setTag(attractionData);
mapidDisplay.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
focusLication(v, event);
return true;
}
});
Log.d(TAG,
"attractionData.getLatitude() ----->"
+ attractionData.getLatitude()
+ " attractionData.getLongitude()---> "
+ attractionData.getLongitude());
if (attractionData.getLatitude() != 0
&& attractionData.getLongitude() != 0) {
mapidDisplay.setText(" " + abbrMapId + (position + 1) + " ");
mapidDisplay.setVisibility(View.VISIBLE);
} else {
mapidDisplay.setVisibility(View.GONE);
}
} else {
ImageView acceptRecommend = (ImageView) view
.findViewById(R.id.acceptRecommend);
ImageView rejectRecommend = (ImageView) view
.findViewById(R.id.rejectRecommend);
acceptRecommend.setVisibility(View.VISIBLE);
rejectRecommend.setVisibility(View.VISIBLE);
acceptRecommend.setTag(attractionData);
rejectRecommend.setTag(attractionData);
acceptRecommend.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
AttractionData data = (AttractionData) ((ImageView) v).getTag();
((CityPreferences) activity.getApplication()).updateRecommended(data);
items.remove(position);
notifyDataSetChanged();
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
break;
}
return true;
}
});
rejectRecommend.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
AttractionData data = (AttractionData) ((ImageView) v).getTag();
long id = data.getId();
((CityPreferences) activity.getApplication()).deleteSavedAttractions(data);
data.setStatus("unselect");
items.remove(position);
notifyDataSetChanged();
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
break;
}
return true;
}
});
}
textAddress.setText(attractionData.getAddress());
TextView distance = (TextView) view.findViewById(R.id.distance);
ImageView distanceDir = (ImageView) view
.findViewById(R.id.distancedirection);
Bitmap bitmap = BitmapFactory.decodeResource(activity.getResources(),
R.drawable.navigationdir);
float newRot = new Float(attractionData.getNavigationAngle());
Matrix matrix = new Matrix();
matrix.postRotate(newRot);
// Log.d(TAG, "Roating the Navigation Image : 01" +
// Constants.mOrientation[0]);
if (Constants.mOrientation != null && Constants.mOrientation.length > 0) {
double bearingToTarget = newRot + Constants.mOrientation[0];
double drawingAngle = Math.toRadians(bearingToTarget)
- (Math.PI / 2);
float cos = (float) Math.cos(drawingAngle);
float sin = (float) Math.sin(drawingAngle);
matrix.setSinCos(sin, cos);
Bitmap redrawnBitmap = Bitmap.createBitmap(bitmap, 0, 0,
bitmap.getWidth(), bitmap.getHeight(), matrix, true);
distanceDir.setImageBitmap(redrawnBitmap);
// distanceDir.setRotation(90);
} else {
Bitmap redrawnBitmap = Bitmap.createBitmap(bitmap, 0, 0,
bitmap.getWidth(), bitmap.getHeight(), matrix, true);
distanceDir.setImageBitmap(redrawnBitmap);
}
if (attractionData.getDistance() != null
&& !attractionData.getDistance().equals("")) {
distance.setText(attractionData.getDistance());
} else {
distance.setText("");
}
if (attractionData.getLatitude() != 0.00
&& attractionData.getLongitude() != 0.00) {
distanceDir.setVisibility(View.VISIBLE);
distance.setVisibility(View.VISIBLE);
} else {
distanceDir.setVisibility(View.GONE);
distance.setVisibility(View.GONE);
}
// Log.d(TAG, "end to search distance -->");
LinearLayout llReviews = (LinearLayout) view
.findViewById(R.id.reviewsrating);
llReviews.setVisibility(View.VISIBLE);
GridView gridview = (GridView) view.findViewById(R.id.ratingView);
TextView textRating = (TextView) view.findViewById(R.id.rating);
TextView textReviews = (TextView) view.findViewById(R.id.reviews);
textRating.setText("(" + attractionData.getRating() + ")");
gridview.setAdapter(new ImageAdapter(getContext(), attractionData
.getRating()));
// code for review
if (attractionData.getReview() != null
&& (attractionData.getReview().equals("1") || attractionData
.getReview().equals("0"))) {
textReviews.setText(attractionData.getReview() + " review");
} else if (attractionData.getReview() != null) {
textReviews.setText(attractionData.getReview() + " reviews");
} else {
textReviews.setText("0 review");
}
textReviews.setTag(attractionData.getReviewUrl());
textReviews.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String webURL = (String) v.getTag();
utils.openWebURL(v.getContext(), webURL);
}
});
if (Constants.isDefineNeighbourHood) {
addFavorite.setVisibility(View.GONE);
} else {
if (attractionData.getId() > 0) {
if (menuId != null && menuId.equalsIgnoreCase(Constants.menuFavouritePlaceId)) {
addFavorite.setImageResource(R.drawable.favorite_active);
addFavorite.setVisibility(View.GONE);
attractionData.setStatus("select");
EditAttraction editAttraction = new EditAttraction(activity, false);
itemlayer.setOnLongClickListener(editAttraction);
if (!Constants.isEysonly) {
Loginmyplaces loginmyplaces = new Loginmyplaces(activity);
itemlayer.setOnClickListener(loginmyplaces);
}
} else {
addFavorite.setImageResource(R.drawable.favorite_active);
addFavorite.setVisibility(View.VISIBLE);
attractionData.setStatus("select");
EditAttraction editAttraction = new EditAttraction(activity, true);
itemlayer.setOnLongClickListener(editAttraction);
}
} else {
addFavorite.setVisibility(View.VISIBLE);
addFavorite.setImageResource(R.drawable.favorite);
attractionData.setStatus("unselect");
EditAttraction editAttraction = new EditAttraction(activity,
true);
itemlayer.setOnLongClickListener(editAttraction);
}
}
// Log.d(TAG, "Constants.totalFavorite : status : " +
// attractionData.getStatus() + " for " + attractionData.getName());
addFavorite.setTag(attractionData);
addFavorite.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
AttractionData data = (AttractionData) ((ImageView) v)
.getTag();
ImageView currentpinsave = (ImageView) v
.findViewById(R.id.pinsave);
Log.d(TAG,
"Constants.totalFavorite : status : "
+ data.getStatus());
Log.d(TAG, "Constants.totalFavorite : Resource : "
+ currentpinsave);
if (data.getStatus() != null
&& data.getStatus().equalsIgnoreCase("select")) {
Log.d(TAG, "data.status " + data.getStatus());
currentpinsave.setImageResource(R.drawable.favorite);
currentpinsave.setTag(data);
long id = data.getId();
((CityPreferences) activity.getApplication())
.deleteSavedAttractions(data);
data.setStatus("unselect");
currentpinsave.setImageResource(R.drawable.favorite);
new DeleteFromConstance().execute(id);
} else {
Log.d(TAG, "data.status " + data.getStatus());
currentpinsave
.setImageResource(R.drawable.favorite_active);
currentpinsave.setTag(data);
data.setMenuId(menuId);
streetView.checkPhotoView(data);
((CityPreferences) activity.getApplication())
.saveMyAttractions(data, true);
data.setStatus("select");
utils.checkFavoriteCity(activity, data);
}
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
break;
}
return true;
}
});
if (!isRecommended) {
if (attractionData.getImages() != null) {
Log.d(TAG, "ImageUtils --> inside blob saved");
ImageView placeImage = (ImageView) view
.findViewById(R.id.placeimage);
placeImage.setVisibility(View.VISIBLE);
placeImage.setImageBitmap(attractionData.getImages());
} else {
Log.d(TAG, "ImageUtils --> inside blob not saved");
ImageView placeImage = (ImageView) view
.findViewById(R.id.placeimage);
placeImage.setVisibility(View.GONE);
}
}
ImageView navigationImage = (ImageView) view
.findViewById(R.id.navigationImage);
ImageView streetViewImage = (ImageView) view
.findViewById(R.id.streetview);
if (attractionData.getLatitude() != 0
&& attractionData.getLongitude() != 0) {
navigationImage.setImageResource(R.drawable.navigation);
navigationImage.setTag(attractionData);
navigationImage.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if (utils.isConnectionAvailable(v.getContext())) {
Intent intent = new Intent(v.getContext(), Navigator.class);
AttractionData data = (AttractionData) ((ImageView) v).getTag();
Bundle bundle = new Bundle();
// add data to bundle
bundle.putString("startlatitude", latitute + "");
bundle.putString("startlongitude", longitute + "");
bundle.putString("latitude", data.getLatitude() + "");
bundle.putString("longitude", data.getLongitude() + "");
intent.putExtras(bundle);
v.getContext().startActivity(new Intent(intent).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK));
} else {
Toast.makeText(v.getContext(), v.getContext().getResources().getString(R.string.noconnection), Toast.LENGTH_LONG).show();
}
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
break;
}
return true;
}
});
streetViewImage.setTag(attractionData);
streetViewImage.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
AttractionData data = (AttractionData) v.getTag();
Location location = new Location("");
location.setLatitude(data.getLatitude());
location.setLongitude(data.getLongitude());
streetView.checkStreetView(location);
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
break;
}
return true;
}});
streetViewImage.setVisibility(View.VISIBLE);
navigationImage.setVisibility(View.VISIBLE);
} else {
streetViewImage.setVisibility(View.GONE);
navigationImage.setVisibility(View.GONE);
}
LinearLayout commentLayout = (LinearLayout) view
.findViewById(R.id.commentLayout);
if (attractionData.getComments() != null
&& !attractionData.getComments().trim().equals("")) {
commentLayout.setVisibility(View.VISIBLE);
TextView comment = (TextView) view.findViewById(R.id.comment);
comment.setText(attractionData.getComments());
} else {
commentLayout.setVisibility(View.GONE);
}
ImageView phImage = (ImageView) view.findViewById(R.id.phoneImage);
String phoneNo = attractionData.getPhoneNo();
if (attractionData.getMobileNo() != null
&& !attractionData.getMobileNo().equals("")
&& !attractionData.getMobileNo().equalsIgnoreCase("null")) {
if (phoneNo != null && !phoneNo.equals("")
&& !phoneNo.equalsIgnoreCase("null")) {
phoneNo = phoneNo + ",\n" + attractionData.getMobileNo();
} else {
phoneNo = attractionData.getMobileNo();
}
}
Log.d(TAG, "------------------> phoneNo " + phoneNo);
if (phoneNo != null && !phoneNo.equals("") && !phoneNo.equalsIgnoreCase("null")) {
textPhone.setText(phoneNo);
textPhone.setVisibility(View.VISIBLE);
phImage.setVisibility(View.VISIBLE);
phImage.setImageResource(R.drawable.phone);
phImage.setTag(phoneNo);
phImage.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
String phone = (String) ((ImageView) v).getTag();
Log.d(TAG, "onTouch phone--" + phone);
utils.dailPhone(v.getContext(), phone);
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
break;
}
return true;
}
});
} else {
phImage.setVisibility(View.GONE);
textPhone.setVisibility(View.GONE);
}
LinearLayout htmllayout = (LinearLayout) view
.findViewById(R.id.htmllayout);
if (attractionData.getHtmlAttributions() != null
&& !attractionData.getHtmlAttributions().equals("")
&& !attractionData.getHtmlAttributions().equalsIgnoreCase(
"null")) {
htmllayout.setVisibility(View.VISIBLE);
TextView htmlAttributions = (TextView) view
.findViewById(R.id.htmlAttributions);
TextView htmlAttributionsLink = (TextView) view
.findViewById(R.id.htmlAttributionsLink);
htmlAttributions.setText(attractionData.getHtmlAttributions());
htmlAttributionsLink.setText(attractionData
.getHtmlAttributionsLink());
htmlAttributionsLink.setTag(attractionData);
htmlAttributionsLink.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
AttractionData data = (AttractionData) ((TextView) v)
.getTag();
utils.openWebURL(v.getContext(),
data.getHtmlAttributionsUrl());
new Intent(Intent.ACTION_VIEW);
return true;
}
});
} else {
htmllayout.setVisibility(View.GONE);
}
// ********************************************* changing for showing
// the zagat review and price level
String priceTag = attractionData.getPriceTag();
String zagatReview = attractionData.getZagatReview();
Log.d(TAG, "Extra Parameter Setup : " + attractionData.getfName()
+ " URL : " + attractionData.getReviewUrl());
Log.d(TAG, "Extra Parameter Setup : priceTag : " + priceTag
+ " zagatReview : " + zagatReview);
if (priceTag != null && !priceTag.equals("")) {
((TextView) view.findViewById(R.id.pricelevelvalue))
.setText(priceTag);
} else {
view.findViewById(R.id.pricelevelvalue).setVisibility(View.GONE);
}
if (zagatReview != null && !zagatReview.equals("")) {
view.findViewById(R.id.moredetail_review).setVisibility(
View.VISIBLE);
((TextView) view.findViewById(R.id.zagatreviewvalue))
.setText(zagatReview);
} else {
view.findViewById(R.id.moredetail_review).setVisibility(View.GONE);
}
Reservation reservation = attractionData.getReservation();
List<PlaceMenu> menus = attractionData.getMenu();
if ((reservation != null) || (menus != null && !menus.isEmpty())) {
view.findViewById(R.id.moredetail_menu_reservation).setVisibility(
View.VISIBLE);
TextView reservationTextView = (TextView) view
.findViewById(R.id.reservationvalues);
if (reservation != null && reservation.getName() != null
&& !reservation.getName().equals("")) {
Log.d(TAG,
"Extra Parameter Setup : reservation "
+ reservation.getName() + " URL : "
+ reservation.getUrl());
view.findViewById(R.id.reservation).setVisibility(View.VISIBLE);
reservationTextView.setVisibility(View.VISIBLE);
reservationTextView.setText(reservation.getName());
reservationTextView.setTag(reservation.getUrl());
reservationTextView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
utils.openWebURL(v.getContext(),
(String) ((TextView) v).getTag());
new Intent(Intent.ACTION_VIEW);
return true;
}
});
} else {
view.findViewById(R.id.reservation).setVisibility(View.GONE);
reservationTextView.setVisibility(View.GONE);
}
TextView placemenuTextView = (TextView) view
.findViewById(R.id.placemenu);
if (menus != null && !menus.isEmpty()) {
Log.d(TAG,
"Extra Parameter Setup : Menu Size : " + menus.size());
placemenuTextView.setVisibility(View.VISIBLE);
placemenuTextView.setTag(menus);
placemenuTextView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
List<PlaceMenu> placeMenu = (List<PlaceMenu>) ((TextView) v).getTag();
ArrayList<DialogData> data = new ArrayList<DialogData>();
for (int i = 0; i < placeMenu.size(); i++) {
DialogData dialogData = new DialogData();
dialogData.setName(placeMenu.get(i).getName());
dialogData.setValue(placeMenu.get(i).getUrl());
dialogData.setType("url");
data.add(dialogData);
}
utils.showPopupDailog(v.getContext(), data, "Menu");
new Intent(Intent.ACTION_VIEW);
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
break;
}
return true;
}
});
} else {
placemenuTextView.setVisibility(View.GONE);
}
} else {
view.findViewById(R.id.moredetail_menu_reservation).setVisibility(
View.GONE);
}
if (attractionData.getHotelReview() != null) {
PlaceHotelReview hotelReview = null;
TextView textView = null;
textView = (TextView) view.findViewById(R.id.hotelreviewtext);
if (menuId != null && menuId.equals(Constants.menuHotelId)) {
textView.setText(R.string.hotelPricing);
} else {
textView.setText(R.string.hotelreview);
}
Log.d(TAG, "Hotel Review Step 02 : ");
LinearLayout rl = (LinearLayout) view
.findViewById(R.id.hotelreview);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
view.findViewById(R.id.hotelreview).setVisibility(View.VISIBLE);
rl.removeAllViews();
rl.addView(textView, lp);
for (int i = 0; i < attractionData.getHotelReview().size(); i++) {
hotelReview = attractionData.getHotelReview().get(i);
Log.d(TAG, "Hotel Review Step 03 : " + hotelReview);
textView = new TextView(activity);
Log.d(TAG, "Hotel Review Step 04 : " + hotelReview.getName());
Log.d(TAG, "Hotel Review Step 05 : " + hotelReview.getReviews());
textView.setText(hotelReview.getName().replaceAll("\"", ""));
if (i == attractionData.getHotelReview().size() - 1) {
textView.setPadding(5, 5, 0, 5);
} else if (i == attractionData.getHotelReview().size() - 1) {
textView.setPadding(5, 0, 0, 5);
} else {
textView.setPadding(5, 5, 0, 0);
}
textView.setTextColor(Color.parseColor("#0000ff"));
textView.setTag(hotelReview);
Log.d(TAG, "Hotel Review Step 05 : ");
textView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
PlaceHotelReview hotelReview = (PlaceHotelReview) v.getTag();
utils.openWebURL(v.getContext(), hotelReview.getUrl().replaceAll("\"", ""));
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
break;
}
return true;
}
});
rl.addView(textView, lp);
}
} else {
view.findViewById(R.id.hotelreview).setVisibility(View.GONE);
}
TextView openCloseTime = (TextView) view
.findViewById(R.id.openclosedesc);
if (attractionData.getOpenCloseDesc() != null
&& !attractionData.getOpenCloseDesc().equals("")
&& !attractionData.getOpenCloseDesc().equalsIgnoreCase("null")) {
openCloseTime.setText(attractionData.getOpenCloseDesc());
} else {
openCloseTime.setVisibility(View.GONE);
}
itemlayer.setOnTouchListener(new DetectMotion(activity, isAddressBook));
if (position % 2 == 0)
view.setBackgroundResource(R.drawable.listshape);
else
view.setBackgroundResource(R.drawable.favoritebody);
return view;
}
private void focusLication(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
AttractionData ad = (AttractionData) v.getTag();
Constants.isMaptobeLoaded = true;
if (ad.getLatitude() != 0 && ad.getLongitude() != 0) {
if (Constants.isDefineNeighbourHood) {
if (Constants.focusLocationNH == null) {
Constants.focusLocationNH = new Location("");
}
Constants.focusLocationNH.setLatitude(ad.getLatitude());
Constants.focusLocationNH.setLongitude(ad.getLongitude());
if (Constants.myNeighborHoodLocation == null) {
Constants.myNeighborHoodLocation = new Location("");
}
Constants.myNeighborHoodLocation.setLatitude(ad
.getLatitude());
Constants.myNeighborHoodLocation.setLongitude(ad
.getLongitude());
} else {
if (Constants.focusLocation == null) {
Constants.focusLocation = new Location("");
}
Constants.focusLocation.setLatitude(ad.getLatitude());
Constants.focusLocation.setLongitude(ad.getLongitude());
}
activity.finish();
if (isAddressBook) {
Constants.isPABImportant = true;
activity.overridePendingTransition(R.anim.slide_in_left,
R.anim.slide_out_left);
} else {
Constants.isPABImportant = false;
activity.overridePendingTransition(R.anim.slide_out_right,
R.anim.slide_in_right);
}
}
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
break;
}
}
感谢任何帮助。
答案 0 :(得分:1)
尝试这样
list.clear();
adpater.notifyDataSetChanged();
///从列表中删除项目。
adapter.clear();
adpater.notifyDataSetChanged();
并非所有Adapters都有clear()方法。 ArrayAdapter可以,但ListAdapter或SimpleAdapter不是
答案 1 :(得分:0)
清除适配器的数据后,只需通知列表视图我猜searchAdapter是你的适配器。 SearchAdapter是一个自定义适配器,您需要根据适配器类型清除数据,然后调用notifyDataSetChanged。
答案 2 :(得分:0)
这是用于清除按钮单击
上的列表视图数据的代码Button yourbutton; // init it
yourButon.setOnClickListener(new OnClickListener(){
yourList.clear(); // this list which you hava passed in Adapter for your listview
yourAdapter.notifyDataSetChanged(); // notify to listview for refresh
});