- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
请帮帮我。
我只想知道是否可以在 onEditorAction
中的 setOnEditorActionListener
中传递两个或多个值?
正如您在代码值中看到的那样?
我在我的数量中添加了 setOnEditorActionListener
..
我还想在 onEditorAction
中传递 mcustomers_basket_id
的值
mcustomers_basket_id = customers_basket_id.getText().toString();
quantity.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_NEXT || event.getAction() == KeyEvent.KEYCODE_BACK || event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
String hqty;
hqty = v.getText().toString();
if (hqty.matches("") || hqty.matches("0")) {
Toast.makeText(context, "Please enter a valid quantity.", Toast.LENGTH_SHORT).show();
invalidquanity();
} else {
Toast.makeText(context, hqty+" ", Toast.LENGTH_SHORT).show();
//return true; // consume.
}
}
return false; // pass on to other listeners.
}
});
我将 listview
与数组项一起使用。
这里是完整的代码..
ListViewAdapter.java
package com.example.administrator.mosbeau;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.FragmentManager;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
/**
* Created by Administrator on 11/2/2015.
*/
@SuppressWarnings("deprecation")
public class ListViewAdapter extends BaseAdapter {
boolean expanded = false;
String mgcustomersid, mgcountryid, mproducts_id, mcustomers_basket_id;
public static final int CONNECTION_TIMEOUT = 1000 * 15;
public static final String SERVER_ADDRESS = "http://shop.mosbeau.com.ph/android/";
String myJSONupdateCartQty;
JSONArray jsonarrayupdateCartQty;
ProgressDialog mProgressDialog;
// Declare Variables
Context context;
LayoutInflater inflater;
ArrayList<HashMap<String, String>> data;
HashMap<String, String> resultp = new HashMap<String, String>();
public ListViewAdapter(Context context,
ArrayList<HashMap<String, String>> arraylist) {
this.context = context;
data = arraylist;
}
@Override
public int getCount() {
return data.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
public View getView(final int position, View convertView, ViewGroup parent) {
// Declare Variables
TextView products_id;
TextView products_name;
TextView products_price;
ImageView products_image;
EditText quantity;
TextView totalprice;
TextView pcustomersid;
TextView pcountryid;
TextView customers_basket_id;
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.cart_listview_item, parent, false);
// Get the position
resultp = data.get(position);
// Locate the TextViews in product_gridview_item.xml
products_id = (TextView) itemView.findViewById(R.id.products_id);
products_name = (TextView) itemView.findViewById(R.id.products_name);
products_price = (TextView) itemView.findViewById(R.id.products_price);
quantity = (EditText) itemView.findViewById(R.id.quantity);
totalprice = (TextView) itemView.findViewById(R.id.products_price_total);
// Locate the ImageView in product_gridview_item.xml
products_image = (ImageView) itemView.findViewById(R.id.products_image);
// Capture position and set results to the TextViews
products_id.setText(resultp.get(CartFragment.products_id));
products_name.setText(resultp.get(CartFragment.products_name));
products_price.setText(resultp.get(CartFragment.products_price));
quantity.setText(resultp.get(CartFragment.customers_basket_quantity));
totalprice.setText(resultp.get(CartFragment.products_price_total));
// Capture position and set results to the ImageView
Glide.with(context).load(resultp.get(CartFragment.products_image)).diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.productloading).into(products_image);
int color = 0xffffffff;
itemView.setBackgroundColor(color);
pcustomersid = (TextView) itemView.findViewById(R.id.customersid);
pcustomersid.setText(resultp.get(CartFragment.pcustomersid));
pcountryid = (TextView) itemView.findViewById(R.id.countryid);
pcountryid.setText(resultp.get(CartFragment.pcountryid));
customers_basket_id = (TextView) itemView.findViewById(R.id.customers_basket_id);
customers_basket_id.setText(resultp.get(CartFragment.customers_basket_id));
mgcustomersid = pcustomersid.getText().toString();
mgcountryid = pcountryid.getText().toString();
mproducts_id = products_id.getText().toString();
mcustomers_basket_id = customers_basket_id.getText().toString();
quantity.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_NEXT || event.getAction() == KeyEvent.KEYCODE_BACK || event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
String hqty;
hqty = v.getText().toString();
if (hqty.matches("") || hqty.matches("0")) {
Toast.makeText(context, "Please enter a valid quantity.", Toast.LENGTH_SHORT).show();
invalidquanity();
} else {
Toast.makeText(context, hqty+" ", Toast.LENGTH_SHORT).show();
//return true; // consume.
}
}
return false; // pass on to other listeners.
}
});
return itemView;
}
public void invalidquanity(){
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context);
dialogBuilder.setMessage("Please enter a valid quantity.");
dialogBuilder.setNegativeButton("OK", null);
AlertDialog dialog = dialogBuilder.show();
TextView messageText = (TextView)dialog.findViewById(android.R.id.message);
messageText.setGravity(Gravity.CENTER);
dialog.show();
}
}
请帮帮我..
最佳答案
I just want to know if it is possible to pass two or more value inside setOnEditorActionListener in onEditorAction?
是的,可以使用 setTag/getTag
方法。这样做:
quantity.setTag(mcustomers_basket_id);
并将值设置为:
int mcustomers_basket_id_=Integer.parseInt(v.getTag().toString());
关于android - 在 ListView 适配器内的 setOnEditorActionListener 中传递多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33495856/
我刚刚学习 java/android,我在 setOnEditorActionListener 方面遇到问题。 我的问题是,第一次网页只能通过单击“Go”按钮加载,而不是通过键盘上的“完成”按钮加载。
尝试将事件监听器连接到 Android studio 中的 EditText 字段,但出现错误。这是我的事件监听器: TextView editText = new TextView (this);
我更新了我的应用程序,但现在监听器不工作了。 我将此 Activity 用于类似的操作: 1. EditText (IP地址) & AutoCompleteTextView (子网掩码) 2. Edi
我对 setOnEditorActionListener 有疑问,我不明白为什么它会使应用程序崩溃。我按照 Android 开发者网站上的指南搜索了大约 2 个小时,但我找不到解决方案......代码
我想创建一个布局,用户在其中键入艺术家姓名,当他在虚拟键盘上按下搜索时,会显示艺术家列表。 View rootView = (View) inflater.inflate(R.layout.fragm
我正在尝试在按下输入按钮时为 EditText 设置一个监听器。但它根本没有触发。我在装有 Android 4.2.2 的 LG Nexus 4 上对此进行了测试。 setOnEditorAction
这个问题在这里已经有了答案: How to watch multiple edittext boxes for a softkey enter or done press? (2 个答案) 关闭 1
我一直在尝试这个IME_ACTION //Listening to the keyboard action mSearchEditText.setOnEditorActionListener
我陷入了一个问题,当我在 xml 中使用 inputtype 作为 textmultiline 并在 edittext 中使用imeiOptions 作为 KEYCODE_ENTER 时。然后我的 s
当用户按下 EditText 中的输入按钮时,我正在尝试做一些事情(它是多行 editText 意味着用户可以写多行) 只是我想检测是否按下了回车键 使用的代码如下所示 听众是 mBodyText
请帮帮我。 我只想知道是否可以在 onEditorAction 中的 setOnEditorActionListener 中传递两个或多个值? 正如您在代码值中看到的那样? 我在我的数量中添加了 se
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
有人可以提供一个解决方案来为软键盘 DONE 按钮获取工作监听器,和/或解释我当前方法中做错了什么吗? 我的 Xml 和 Java 设置 在 Xml 中,有一个简单的 EditText 设置为 and
这个问题不太可能帮助任何 future 的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visit
我在 developer.android.com 上看到这段代码用于处理软键盘的 IME_ACTION: EditText editText = (EditText) findViewById(R.i
当我在 EditText(密码)中按 Enter 时,它会转到一个新行,然后如果执行 setOnEditorActionListener,那么我的密码将不正确(因为添加了 Enter)。有什么解决办法
我是一名优秀的程序员,十分优秀!