能不能具体点,我是菜鸟。 我的代码: ScoreInformation.javapublic class ScoreInformation extends Activity { private ListView lv; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
ArrayList<HashMap<String,String>> mylist = new ArrayList<HashMap<String,String>>(); HashMap<String,String> map = new HashMap<String,String>(); map.put("ID", "学号"); map.put("Name", "姓名"); map.put("Course", "科目"); map.put("Score", "成绩"); mylist.add(map); for(int i=0; i<Datainfo.studentLength; i++){ int j=0; HashMap<String,String> map1 = new HashMap<String,String>(); map1.put("ID",Datainfo.data[j++][i]); map1.put("Name", Datainfo.data[j++][i]); map1.put("Course", Teacherinfo.course); if(Datainfo.data[j++][i].equals("null")){ map1.put("Score", ""); }else{ map1.put("Score", Datainfo.data[j++][i]); } mylist.add(map1); } SpecialAdapter adapter = new SpecialAdapter(this, mylist, R.layout.scoreinformation, new String[]{ "ID","Name","Course","Score"}, new int[] { R.id.tv1,R.id.tv2,R.id.tv3,R.id.tv4} );
lv = new ListView(this); lv.setHorizontalScrollBarEnabled(true); lv.setAdapter(adapter); HorizontalScrollView hsv = new HorizontalScrollView(this); hsv.addView(lv); setContentView(hsv); } } 其中“tv4”是记录分数的EditTextSpecialAdapter.java public class SpecialAdapter extends SimpleAdapter { private int[] colors = new int[]{ 0x30FF0000, 0x300000FF }; public SpecialAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) { super(context, data, resource, from, to); // TODO Auto-generated constructor stub } @Override public View getView(int position, View convertView, ViewGroup parent) { View view = super.getView(position, convertView, parent); int colorPos = position % colors.length; if(colorPos==1){ view.setBackgroundColor(Color.argb(250, 255, 255, 255)); }else{ view.setBackgroundColor(Color.argb(250, 224, 243, 250)); } return view; } }
if (s.params.get(j).tpy.equals("L")){ et[i][j].setEnabled(true); et[i][j].setText("0"); et[i][j].setInputType(InputType.TYPE_NULL); et[i][j].setEnabled(false); et[i][j].setClickable(false);
} DTextWatcher watcher = new DTextWatcher(et[i][j], handler); et[i][j].addTextChangedListener(watcher); et[i][j].setImeOptions(EditorInfo.IME_ACTION_UNSPECIFIED);
et[i][j].setOnFocusChangeListener(new OnFocusChangeListener() { public void onFocusChange(View view, boolean hasChange){
if (view.getTag(R.string.tpy).equals("L")){ view.setClickable(false); return; } } } }); }
弱弱的问下 你的EditText的二位数组是怎么申请的?我怎么老是空指针啊?
//声明 public EditText [][] et = null;//申请 et = new EditText[rowcount][colcount];//为每一项申请 for(int j = 0; j < colcount;j++){ et[i][j] = new EditText(c); }
我的代码:
ScoreInformation.javapublic class ScoreInformation extends Activity {
private ListView lv;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ArrayList<HashMap<String,String>> mylist = new ArrayList<HashMap<String,String>>();
HashMap<String,String> map = new HashMap<String,String>();
map.put("ID", "学号");
map.put("Name", "姓名");
map.put("Course", "科目");
map.put("Score", "成绩");
mylist.add(map);
for(int i=0; i<Datainfo.studentLength; i++){
int j=0;
HashMap<String,String> map1 = new HashMap<String,String>();
map1.put("ID",Datainfo.data[j++][i]);
map1.put("Name", Datainfo.data[j++][i]);
map1.put("Course", Teacherinfo.course);
if(Datainfo.data[j++][i].equals("null")){
map1.put("Score", "");
}else{
map1.put("Score", Datainfo.data[j++][i]);
}
mylist.add(map1);
} SpecialAdapter adapter = new SpecialAdapter(this, mylist, R.layout.scoreinformation,
new String[]{ "ID","Name","Course","Score"},
new int[] { R.id.tv1,R.id.tv2,R.id.tv3,R.id.tv4}
);
lv = new ListView(this);
lv.setHorizontalScrollBarEnabled(true);
lv.setAdapter(adapter);
HorizontalScrollView hsv = new HorizontalScrollView(this);
hsv.addView(lv);
setContentView(hsv);
}
}
其中“tv4”是记录分数的EditTextSpecialAdapter.java
public class SpecialAdapter extends SimpleAdapter {
private int[] colors = new int[]{
0x30FF0000, 0x300000FF
};
public SpecialAdapter(Context context, List<? extends Map<String, ?>> data,
int resource, String[] from, int[] to) {
super(context, data, resource, from, to);
// TODO Auto-generated constructor stub
} @Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
int colorPos = position % colors.length;
if(colorPos==1){
view.setBackgroundColor(Color.argb(250, 255, 255, 255));
}else{
view.setBackgroundColor(Color.argb(250, 224, 243, 250));
}
return view;
}
}
------------------------------------------------------------------------
在这里加listener之类 在listener里处理
谢谢你的提醒 我试了一下OnItemClickListener 但是他居然没有调用 这是什么情况?
et[i][j] = new EditText(c);
et[i][j].setTag(R.string.flag, null);
et[i][j].setTag(R.string.colsname, s.params.get(j).col);
et[i][j].setTag(R.string.max, s.params.get(j).max);
et[i][j].setTag(R.string.min, s.params.get(j).min);
et[i][j].setTag(R.string.pcs, s.params.get(j).pcs);
et[i][j].setTag(R.string.tpy, s.params.get(j).tpy);
et[i][j].setTag(R.string.id, id);
et[i][j].setTextSize(Devicer.getFontNormal());
if (j == colcount-1 && flag){
et[i][j].setTag(R.string.max, String.valueOf(Integer.MAX_VALUE));
}
layout.addView(et[i][j], width/(colcount+1)+20, Devicer.getTextViewHeight());
if (s.params.get(j).tpy.equals("N")){
et[i][j].setInputType(InputType.TYPE_CLASS_NUMBER);
et[i][j].setText("0");
if(Integer.valueOf(s.params.get(j).pcs) > 0){
et[i][j].setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
}
}
if (s.params.get(j).tpy.equals("L")){
et[i][j].setEnabled(true);
et[i][j].setText("0");
et[i][j].setInputType(InputType.TYPE_NULL);
et[i][j].setEnabled(false);
et[i][j].setClickable(false);
} DTextWatcher watcher = new DTextWatcher(et[i][j], handler);
et[i][j].addTextChangedListener(watcher);
et[i][j].setImeOptions(EditorInfo.IME_ACTION_UNSPECIFIED);
et[i][j].setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View view, boolean hasChange){
if (view.getTag(R.string.tpy).equals("L")){
view.setClickable(false);
return;
} }
}
});
}
//声明
public EditText [][] et = null;//申请
et = new EditText[rowcount][colcount];//为每一项申请
for(int j = 0; j < colcount;j++){
et[i][j] = new EditText(c);
}
第一个问题大家有建议没?
关于这个问题的阐述:
点击edittext后会出现软键盘 然后正常情况下 点击返回键 应该是软键盘消失 edittext中出现你刚填写的字符 但是实际情况是 点击完后 edittext内容为空了
主要思路是 自定义一个适配器,在适配器中找到editText,对editText增加一个检测文字改变事件。事件里面会有修改前,修改时,修改后的各种参数,找到想要的保存下来就好了。
上面各位大大已经讲得差不多了,代码也只是简略代码,希望能给大家启发class mylistphone{
private TextView tv;
private EditText ed;
}
class myAdapter extends BaseAdapter{
private Context ctx;
private ArrayList al ;
private String myend;
private LayoutInflater in;
public myAdapter(Context ctx , ArrayList al ){
this.ctx = ctx;
this.al = al;
}
public int getCount() {
return al.size();
} @Override
public Object getItem(int position) {
return al.get(position);
} @Override
public long getItemId(int position) {
return position;
} @Override
public View getView(int position, View view, ViewGroup parent) {
// String after="";
// final StringBuffer sb = new StringBuffer();
mylistphone mylist = new mylistphone();
in = LayoutInflater.from(ctx);
View v = in.inflate(R.layout.lvphone, null);
mylist.tv = (TextView) v.findViewById(R.id.tvlvphonetype);
mylist.ed = (EditText)v.findViewById(R.id.edlvphonenumber);
mylist.tv.setText(((HashMap)al.get(position)).get("type").toString());
String be = ((HashMap)al.get(position)).get("phonenumber").toString();
mylist.ed.setText(((HashMap)al.get(position)).get("phonenumber").toString());
mylist.ed.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
// System.out.println("s:"+s+",start:"+start+",before:"+before+",count:"+count);
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// System.out.println("s:"+s+",start:"+start+",after:"+after+",count:"+count);
}
public void afterTextChanged(Editable s) {
// System.out.println(s.toString());
// sb.append(s.toString());
myend = s.toString();
}
});
if(be.equals(myend)|| myend==null || myend==""){
// mylist.ed.setText(myend);
myend="";
}else{
// System.out.println(myend+",ttttttttttttttttt");
mylist.ed.setText(myend);
myend="";
}
return v;
}
}
我试了你说的方法,还是没有解决 EditText 编辑完毕后,点击返回键后内容消失。
楼主,你的第一个问题解决了没?