标签:数字键盘
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();
}
});
}
GridView+PopupWindow自界说数字键盘
标签:数字键盘
,