网上找了很多方法:
1、在Listview中设置android:focusable="true"
2、在父控件设置android:focusable="true" android:focusableInTouchMode="true"
3、在ListView中添加 android:descendantFocusability="beforeDescendants"
奇怪我都没有实现。最后用了一下方法:
使用Textview,设置Textview点击事件:弹出携带EditText的AlertDialog来实现输入。
点击事件代码:
holder.Text.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Builder dialog = new AlertDialog.Builder(context);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout layout = (LinearLayout)inflater.inflate(R.layout.set_num_dialog, null);
dialog.setView(layout);
et_search = (EditText)layout.findViewById(R.id.set_num_edit);
dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
String searchC = et_search.getText().toString();
doSomeThing();
}
}).setNegativeButton("取消",null).show();
}
});
布局代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dip"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="vertical"
android:focusable="true"
android:padding="20dip" >
<EditText
android:id="@+id/set_num_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:hint="数量"
android:imeOptions="actionDone"
android:inputType="number" />
</LinearLayout>