我的应用程序是条形码阅读器,用户读取条形码ID即可将其设置为Textview,他可以在editText中输入产品编号。我在listview中实现,其中包括textview和editText。当用户扫描到条形码编号时,我在textView上对其进行了设置,但是我希望在设置为文本后自动按顺序聚焦编辑文本。我该怎么做?
编辑!! 我已经添加请求重点,但始终关注1. editText,并且当扫描2.条形码时1.editText值再次取“ 0”;
这是我的listView;
update wp_postmeta set meta_value = 'show' where meta_key = 'blog_post_sidebar';
这是我的适配器;
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/ID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
android:ellipsize="end"
android:padding="5dp"
android:singleLine="true" />
<EditText
android:id="@+id/Quantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:padding="5dp"
android:singleLine="true"
android:inputType="number">
<requestFocus />
</EditText>
</LinearLayout>
这是活动;
public class ListViewAdapter extends BaseAdapter {
public ArrayList<Model> productList;
Activity activity;
public ListViewAdapter(Activity activity, ArrayList<Model> productList) {
super();
this.activity = activity;
this.productList = productList;
}
@Override
public int getCount() {
return productList.size();
}
@Override
public Object getItem(int position) {
return productList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
private class ViewHolder {
TextView ID;
EditText Quantity;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
LayoutInflater inflater = activity.getLayoutInflater();
if (convertView == null) {
convertView = inflater.inflate(R.layout.listview_row, null);
holder = new ViewHolder();
holder.ID = (TextView) convertView.findViewById(R.id.ID);
holder.Quantity = (EditText) convertView.findViewById(R.id.Quantity);;
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Model item = productList.get(position);
holder.ID.setText(item.getID().toString());
holder.Quantity(String.valueOf(item.getQuantity()));
return convertView;
}
}
答案 0 :(得分:0)
在将所有视图设置为类似后,只需在您的EditText上设置request focus
//your other view like textview and imageview if you have
Quantity.requestFocus();
答案 1 :(得分:0)
尝试此代码。
md5
和xml代码。
edittextbox.requestFocus();
答案 2 :(得分:0)
在您的Adapter getView()方法中编写此
holder.ID.addTextChangedListener(new TextWatcher() { @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
holder.Quantity.requestFocus();
}
});
答案 3 :(得分:0)
这是一种解决方法,它将强制将键盘显示在目标editText上。
InputMethodManager keyboard = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
keyboard.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
答案 4 :(得分:0)
尝试一下:
public void populateList(String ID){
item = new Model(ID,0);
mlist.add(item);
adapter.notifyDataSetChanged();
ListView listView = (ListView) findViewById(R.id.listview);
listView.smoothScrollToPosition(mlist.size() - 1);
LinearLayout childView = (LinearLayout)listView.getChildAt(listView.getLastVisiblePosition() - listView.getFirstVisiblePosition());
EditText quantity = (EditText)childView.findViewById(R.id.Quantity);
quantity.requestFocus();
}
希望有帮助!