1
我有一個活動,在按鈕點擊(mConfirm2)時,它將把用戶帶到一個新的活動。問題是,如果用戶偶然在按鈕上多次點擊而不是收到意外錯誤,因此我相信唯一的解決方案就是隻允許一次點擊,不管用戶點擊多少次在按鈕上,它只會計算第一次點擊。限制按鈕只能點擊一次
下面是活動
public class CasualEventsSingleItemActivity extends Activity {
// Declare Variables
String list_item_name;
String list_item_description;
String list_item_bac;
String list_item_price;
String list_item_location;
String list_item_purchase_code;
String single_list_item_description;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_events_single_item);
ImageLoader mImageLoader = new ImageLoader(Volley.newRequestQueue(this),
new ImageLoader.ImageCache() {
private final LruCache<String, Bitmap>
cache = new LruCache<String, Bitmap>(20);
@Override
public Bitmap getBitmap(String url) {
return cache.get(url);
}
@Override
public void putBitmap(String url, Bitmap bitmap) {
cache.put(url, bitmap);
}
});
Intent i = getIntent();
list_item_name = i.getStringExtra("list_item_name");
list_item_location = i.getStringExtra("list_item_location");
list_item_bac = i.getStringExtra("list_item_bac");
list_item_price = i.getStringExtra("list_item_price");
list_item_purchase_code = i.getStringExtra("list_item_purchase_code");
single_list_item_description = i.getStringExtra("single_list_item_description");
TextView txtname = (TextView) findViewById(R.id.name);
TextView txtlocation = (TextView) findViewById(R.id.location);
TextView txtsdescription = (TextView) findViewById(R.id.sdescription);
NetworkImageView hsvimage1 = (NetworkImageView) findViewById(R.id.hsvimage1);
NetworkImageView hsvimage2 = (NetworkImageView) findViewById(R.id.hsvimage2);
NetworkImageView hsvimage3 = (NetworkImageView) findViewById(R.id.hsvimage3);
// Get image URLs from your previous network request...
// I could not determine where this is stored from code in your question.
String url1 = list_item_bac; // e.g. http://example.com/images/image1.png
String url2 = list_item_bac;
String url3 = list_item_bac;
// Set the URL of the image that should be loaded into this view, and
// specify the ImageLoader that will be used to make the request.
hsvimage1.setImageUrl(url1, mImageLoader);
hsvimage2.setImageUrl(url2, mImageLoader);
hsvimage3.setImageUrl(url3, mImageLoader);
// Set results to the TextViews
txtname.setText(list_item_name);
txtlocation.setText(list_item_location);
txtsdescription.setText(single_list_item_description);
Button mConfirm2 = (Button)findViewById(R.id.bConfirm2);
mConfirm2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ParseUser currentUser = ParseUser.getCurrentUser();
// Create the class and the columns
currentUser.saveInBackground();
currentUser.put("ActivityName", list_item_name);
currentUser.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
setProgressBarIndeterminateVisibility(false);
if (e == null) {
// Success!
Intent intent = new Intent(CasualEventsSingleItemActivity.this, usermatch.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
else {
AlertDialog.Builder builder = new AlertDialog.Builder(CasualEventsSingleItemActivity.this);
builder.setMessage(e.getMessage())
.setTitle(R.string.signup_error_title)
.setPositiveButton(android.R.string.ok, null);
AlertDialog dialog = builder.create();
dialog.show();
}
}
});
//CasualEventsSingleItemActivity.this.startActivity(new Intent(CasualEventsSingleItemActivity.this, MatchingActivity.class));
}
});
}
}
謝謝。這已經解決了我的問題。 – John 2014-09-23 22:13:15