我正在android上制作数独益智应用程序。这就是我到目前为止所做的
Text Adapter.java
public class TextAdapter extends BaseAdapter {
private Context mContext;
int count = 81;
int k = 1;
private static EditText current = null;
public TextAdapter(Context c) {
mContext = c;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 81;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final EditText editText;
if (convertView == null) {
editText = new EditText(mContext);
editText.setLayoutParams(new GridView.LayoutParams(85, 85));
editText.setPadding(8, 8, 8, 8);
} else {
editText = (EditText) convertView;
}
editText.setId(k);
editText.setGravity(Gravity.CENTER);
editText.setBackgroundResource(R.drawable.rectangle);
InputFilter[] FilterArray = new InputFilter[1];
FilterArray[0] = new InputFilter.LengthFilter(1);
editText.setFilters(FilterArray);
editText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
// TODO Auto-generated method stub
editText.setInputType(InputType.TYPE_NULL);
if (current != null) {
current.setBackgroundResource(R.drawable.rectangle);
}
if (hasFocus) {
current = (EditText) view;
editText.setBackgroundResource(R.drawable.rectangleblue);
}
}
});
return editText;
}
public static EditText getCurrentEditText() {
return current;
}
}
我想用 1-9 的数字随机填充一些编辑文本,但我不知道如何获取每个编辑文本的标识符/名称。这可能吗?如何?
我是android开发的新手。