public class SimpleGridViewTest extends Activity {
EditText editText;
private PopupWindow popupWindow;
private GridView mGridView;
private View contentview;
private List
GridViewAdapter adapter;
private static String editNum = "";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
editText = (EditText) findViewById(R.id.editText);
initData();
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
contentview = inflater.inflate(R.layout.simple_grid_view_test, null);
popupWindow = new PopupWindow(contentview, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
popupWindow.setFocusable(true);
popupWindow.setOutsideTouchable(false);
mGridView = (GridView) contentview.findViewById(R.id.gridview);
adapter = new GridViewAdapter(this, R.layout.grid_view_item, datas);
mGridView.setAdapter(adapter);
mGridView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView> parent, View view, int position, long id) {
String s = datas.get(position);
Toast.makeText(SimpleGridViewTest.this, "xuan" + position, Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView> parent) {
}
});
mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
String num = editText.getText().toString().trim();
editNum = datas.get(position);
if (editNum.equals("OK")) {
editText.setText(editText.getText().toString().trim());
popupWindow.dismiss();
} else if (editNum.equals("")) {
if (num.length() > 0) {
editText.setText(num.substring(0, num.length() - 1));
editText.setSelection(editText.getText().length());
}
} else {
editText.setText(editText.getText().toString().trim() + datas.get(position));
editText.setSelection(editText.getText().length());
}
// Toast.makeText(SimpleGridViewTest.this,"dian"+position,Toast.LENGTH_SHORT).show();
}
});
// 設(shè)置不調(diào)用系統(tǒng)鍵盤(pán)
if (Build.VERSION.SDK_INT <= 10) {
editText.setInputType(InputType.TYPE_NULL);
} else {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
try {
Class cls = EditText.class;
Method setShowSoftInputOnFocus = cls.getMethod("setShowSoftInputOnFocus", boolean.class);
setShowSoftInputOnFocus.setAccessible(true);
setShowSoftInputOnFocus.invoke(editText, false);
} catch (Exception e) {
e.printStackTrace();
}
}
editText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popupWindow.showAsDropDown(editText);
}
});
}
@Override
public void onBackPressed() { //點(diǎn)擊返回按鈕
if (popupWindow.isShowing()) {
popupWindow.dismiss();
return;
}
super.onBackPressed();
}
// 填充數(shù)據(jù)
private void initData() {
for (int i = 0; i < 12; i++) {
if (i < 3) {
datas.add(String.valueOf(i + 1));
} else if (i > 3 && i < 7) {
datas.add(String.valueOf(i));
} else if (i > 7 && i < 11) {
datas.add(String.valueOf(i - 1));
} else if (i == 3) {
datas.add("OK");
} else if (i == 11) {
datas.add("0");
} else {
datas.add("");
}
}
}
}
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。