我有一個帶有複選框的列表,我有兩個按鈕,保存並清除。如何取消複選框,當我點擊清除按鈕,Android:取消選中按鈕上的複選框單擊
public class myProfileActivity extends Activity {
private List<Profile> contacts = null;
private String TAG = "ContactListActivity";
private String inputName;
ListView lvContact;
private Activity _activity;
private ListView mainListView;
private Profile[] itemss;
private ArrayAdapter<Profile> listAdapter;
ArrayList<String> checked = new ArrayList<String>();
public static List<AttractionData> selectedData = new ArrayList<AttractionData>();
private String profileType = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
ContentResolver cr = this.getContentResolver();
setContentView(R.layout.profilelist);
_activity = this;
profileType = getIntent().getExtras().getString("ProfileType");
try {
if (Constants.loadEntries != null) {
Constants.loadEntries.cancel(true);
}
} catch (Exception e) {
Log.e(TAG, "Loading Data------", e);
}
Constants.loadEntries = new LoadEntries();
Constants.loadEntries.execute();
EditText editTxt = (EditText) findViewById(R.id.txtContName);
editTxt.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void afterTextChanged(Editable s) {
inputName = s.toString();
Log.d(TAG, "LoadMoreEntries --> Constants.loadEntries : "
+ Constants.loadEntries);
try {
if (Constants.loadEntries != null) {
Constants.loadEntries.cancel(true);
}
} catch (Exception e) {
Log.e(TAG, "Loading Data--------", e);
}
Constants.loadEntries = new LoadEntries();
Constants.loadEntries.execute();
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
});
Button clearbtn = (Button) findViewById(R.id.clearbtn);
clearbtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
});
Button savebtn = (Button) findViewById(R.id.savebtn);
savebtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (Constants.selectedContacts.size() > 0) {
((CityPreferences) ProfileActivity.this.getApplication())
.storeAllContacts(Constants.selectedContacts);
Constants.selectedContacts= new ArrayList<Profile>();
finish();
v.getContext().startActivity(
new Intent(v.getContext(), PalABActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
});
}
任何幫助表示讚賞。
只有第一個複選框是否清零..? – teekib
獲得空指針異常 – teekib
查看v是你的膨脹視圖??。 – teekib