1

您好先生,我正在从服务器数据库中获取所有菜单名称并附加到编辑文本。如果我按 Enter 意味着它会关注下一个编辑文本。但是如果我在edittext之前按最后一个输入,它就不能专注于最后一个edittext ..

                this is mycode

         public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder holder;


    if (convertView == null) {
        holder = new ViewHolder();
        convertView = inflater.inflate(R.layout.editmainmenulist, null);
        holder.caption = (EditText) convertView
                .findViewById(R.id.editmaimenu);
        holder.caption1=(ImageView) convertView.findViewById(R.id.menuimage);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    //Fill EditText with the value you have in data source
    holder.caption.setText(itemnames[position]);//i append database name to the editext
    holder.caption.setId(position);
    holder.caption1.setImageBitmap(bmps[position]);

    //we need to update adapter once we finish with editing
    holder.caption.setOnFocusChangeListener(new OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus){
                final int position = v.getId();
                final EditText Caption = (EditText) v;
                itemnames[position] = Caption.getText().toString();


                arr.add(Caption.getText().toString());



            }
        }    
    });  



    return convertView;
}
 }

class ViewHolder {
EditText caption;
ImageView caption1;
 }

 class ListItem {
String caption;
    }

这是我的 xml 代码

            <?xml version="1.0" encoding="utf-8"?>
  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >

<ImageView
    android:id="@+id/menuimage"
    android:layout_width="75dip"
    android:layout_height="79dip"
    android:scaleType="centerCrop"
    android:src="@drawable/stub" />

<EditText
    android:id="@+id/editmaimenu"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="80dp"
    android:layout_marginTop="25dp"
    android:singleLine="true" >
</EditText>

</RelativeLayout> 
4

1 回答 1

0

可能是因为edittextsingline=true在其xml中没有..添加它会使其正常工作..

于 2012-04-09T09:25:56.697 回答