91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

GridView+PopupWindow自定義數字鍵盤

發布時間:2020-09-03 08:59:06 來源:網絡 閱讀:666 作者:二零一八 欄目:移動開發

public class SimpleGridViewTest extends Activity {
EditText editText;
private PopupWindow popupWindow;
private GridView mGridView;
private View contentview;
private List<String> datas = new ArrayList<String>();
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();
}
});

    // 設置不調用系統鍵盤
    if (Build.VERSION.SDK_INT <= 10) {
        editText.setInputType(InputType.TYPE_NULL);
    } else {
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        try {
            Class<EditText> 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() {       //點擊返回按鈕
    if (popupWindow.isShowing()) {
        popupWindow.dismiss();
        return;
    }
    super.onBackPressed();
}
// 填充數據
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("");
        }
    }
}

}

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

太康县| 漳平市| 肃宁县| 英山县| 高安市| 凉山| 大悟县| 奈曼旗| 大兴区| 洪湖市| 宜兰市| 密山市| 蒙山县| 玛沁县| 台安县| 南通市| 富裕县| 青浦区| 兴城市| 司法| 鹤岗市| 怀安县| 连云港市| 瓦房店市| 镇坪县| 通江县| 招远市| 穆棱市| 黔南| 沁阳市| 垣曲县| 嵩明县| 新乡市| 和顺县| 合水县| 安达市| 金川县| 隆德县| 天镇县| 湘潭市| 申扎县|