在我的一個Android活動中,LongClickListener()不能與Spinner一起工作。我已經通過編程方式使用了在Api被onCreate()命中時調用的方法。當用戶長按時,我想啓用tdpidSpinner。Spinner.setOnLongClickListener()不能在Android中工作
這裏的方法:
public boolean setTdpId(ArrayList<String> tdpList) {
try {
tdpIdList = tdpList;
runOnUiThread(new Runnable() {
@Override
public void run() {
tdpidSpinner = new Spinner(Activity_Settings.this);
TableRow.LayoutParams tdpid_spinner_params = new
TableRow.LayoutParams(
0, LayoutParams.WRAP_CONTENT, 3f);
tdpidSpinner.setLayoutParams(tdpid_spinner_params);
rowTdpid.addView(tdpidSpinner);
tdpidSpinner.setPrompt("Select TdpId");
tdpidSpinner.setLongClickable(true);
tdpidSpinner.setClickable(true);
if (tdpIdList.size() > 0) {
ArrayAdapter<String> spinnerAdapter = new
ArrayAdapter<String>(
Activity_Settings.this,
android.R.layout.simple_spinner_item,
tdpIdList);
tdpidSpinner.setAdapter(spinnerAdapter);
String tdpid = mActivity.getSharedPreferences(
Utility.PREFERENCE_NAME, Context.MODE_PRIVATE)
.getString(Utility.TDPID, "");
// if(tdpid!=null || tdpid!=""){
if (tdpid != "") {
int spinnerPosition = spinnerAdapter
.getPosition(tdpid);
tdpidSpinner.setSelection(spinnerPosition);
tdpidSpinner.setEnabled(false);
}
tdpidSpinner.setOnLongClickListener(new
View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
tdpidSpinner.setEnabled(true);
return true;
}
});
}
}
這是什麼意思?你能解釋一下嗎:/ –