在尝试从EditText
中CustomAdapter
获取数据时,我遇到了一个非常奇怪的问题。我在SO中经历了一些类似的问题,但无法找到解决方案。 Logcat
曾在非活动的inputconnection上显示此Exception
* gettextbeforecursor,在非活动的inputconnection * 上显示gettextaftercursor。当EditText
为focused
时,会出现softinput
键盘并且我可以在其中写入,但我无法获取已插入Edittext
内的值。我粘贴在Custom Adapter
下面。
MenuCardAdapter.java
public class MenuCardAdapter extends ArrayAdapter<ItemsClass> {
Context activity;
ArrayList<ItemsClass> values = new ArrayList<ItemsClass>();
TextView main_name, item_price;
Button cartBtn;
EditText quantity;
Restaurant_Sql res_sql;
ItemsClass items;
ImageView imageView;
String value;
public MenuCardAdapter(Context activity, int detailListview,
ArrayList<ItemsClass> values) {
// TODO Auto-generated constructor stub
super(activity, detailListview, values);
this.activity = activity;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
// LayoutInflater inflater = (LayoutInflater) activity
// .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(R.layout.detail_menu_items, null);
res_sql = new Restaurant_Sql(activity);
res_sql.Open();
items = values.get(position);
main_name = (TextView) convertView.findViewById(R.id.label_main);
cartBtn = (Button) convertView.findViewById(R.id.cartBtn);
quantity = (EditText) convertView.findViewById(R.id.quantity_value);
item_price = (TextView) convertView.findViewById(R.id.icon_price_home);
imageView = (ImageView) convertView.findViewById(R.id.icon_home);
main_name.setText(items.getItemName());
item_price.setText(items.getItemPrice() + "/-");
if (items.getItemName().equals("Soup")) {
imageView.setImageResource(R.drawable.soup);
}
if (items.getItemName().equals("Dhosa")) {
imageView.setImageResource(R.drawable.dhosa);
}
if (items.getItemName().equals("Continental")) {
imageView.setImageResource(R.drawable.continental);
}
if (items.getItemName().equals("Mutter Panner")) {
imageView.setImageResource(R.drawable.punjabi);
}
if (items.getItemName().equals("Hakka Noodles")) {
imageView.setImageResource(R.drawable.chinese);
}
if (items.getItemName().equals("Butterscotch")) {
imageView.setImageResource(R.drawable.icream);
}
cartBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(activity, quantity.getText().toString().trim(),
Toast.LENGTH_LONG).show();
}
});
return convertView;
}
}
修改
一旦我在stacktrace中得到了这个
W/IInputConnectionWrapper(8152): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper(8152): setComposingText on inactive InputConnection
W/IInputConnectionWrapper(8152): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper(8152): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper(8152): setComposingText on inactive InputConnection
W/IInputConnectionWrapper(8152): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper(8152): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper(8152): setComposingText on inactive InputConnection
W/IInputConnectionWrapper(8152): endBatchEdit on inactive InputConnection
如果有人可以帮忙???
答案 0 :(得分:0)
我知道回答已太晚了,但我发现它对面临同样问题的其他人很有用,
根据评论最初我通过使用ViewHolder
模式解决了问题。这并没有解决问题,但也使view
滚动更顺畅。可在此处找到更多参考资料ViewHolder Reference
作为更好的解决方案,我建议使用RecylcerView
。
RecyclerView
默认提供View
回收更多参考资料可在此处找到:
希望这可以帮助其他人面对同样的问题。感谢