按Enter键意味着它无法将最后的edittext聚焦在android中的自定义列表视图中

时间:2012-04-09 09:19:32

标签: android android-listview

你好先生我从服务器数据库中获取所有的manunames并附加到edittext.if我按下输入意味着它下一个edittext。但如果我按下输入最后一个berfore编辑文本,它就不能在最后一个编辑文本中使用..

                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> 

1 个答案:

答案 0 :(得分:0)

可能是因为edittext在其xml中没有singline=true ..添加将使其正常工作..