在此项目MainFragment中,“自定义适配器”类用于加载列表视图。适配器项是从名为“ PayMode”的Bean类填充的。在该适配器中,有四个“ TextView”和一个“ EditText(allocatedAmt)”。该“ EditText”不是从该Bean类填充的。该“ Edittext” Logcat上的AfterTextChanged正确显示了文本“ editable.toString()”。
现在,我需要为适配器中的“ Edittext(allocatedAmt)”启用一个按钮(在MainFragment中)afterTextChanged列表器。下面是我的代码。
Adapter.java
public class PayModeAdapter extends ArrayAdapter<PayMode> {
Context context;
ArrayList<PayMode> list;
boolean isAllocatedFinished = false;
public PayModeAdapter(Context context, ArrayList<PayMode> list ) {
super(context, R.layout.row_pay_mode, list);
this.context = context;
this.list = list;
}
public boolean isAllocatedFinished() {
return isAllocatedFinished;
}
@Override
public View getView(final int position, final View convertView, final ViewGroup parent) {
LayoutInflater inflater = null;
View row = convertView;
Holder holder = null;
final PayMode payMode = list.get(position);
if (row == null)
{
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.row_pay_mode, parent, false);
holder = new Holder();
holder.mode = (TextView) row.findViewById(R.id.txtPayMode);
holder.date = (TextView) row.findViewById(R.id.txtPayDate);
holder.amt = (TextView)row.findViewById(R.id.txtAmount);
holder.remAmt = (TextView)row.findViewById(R.id.txtRemAmount);
holder.allocatedAmt = (EditText)row.findViewById(R.id.editAlloAmount);
holder.allocatedAmt.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
isAllocatedFinished = true;
Log.d("PAY_MODE_ADAPTER", "VALUE_IS: " + editable.toString());
}
});
row.setTag(holder);
}
else
{
holder = (Holder)row.getTag();
}
holder.mode.setText(payMode.getFPAYMODE_PAID_TYPE());
holder.date.setText(payMode.getFPAYMODE_PAID_DATE());
holder.amt.setText(payMode.getFPAYMODE_PAID_AMOUNT());
holder.remAmt.setText(payMode.getFPAYMODE_PAID_AMOUNT());
holder.allocatedAmt.setText("0.00");
return row;
}
class Holder {
TextView mode;
TextView date;
TextView amt;
TextView remAmt;
EditText allocatedAmt;
}
}
MainFragment.java
onCreateView(){
payModeArrayList = new PayModeDS(getActivity()).getAllPayModeDetails();
payModeAdapter = new PayModeAdapter(getActivity(), payModeArrayList);
if (payModeAdapter.isAllocatedFinished()){
bCancel.setEnabled(true);
}
}
答案 0 :(得分:0)
您可以尝试使用onFocusChange
并覆盖其onFocusChange
方法。
在if(!hasFocus)
{
//your changes here
}
内添加以下代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
namespace XXXX
{
public partial class Form1 : Form
{
public Form1()
{
TopMost = true;
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
serialPort1.PortName = "COM2";
serialPort1.BaudRate = 9600;
serialPort1.Parity = Parity.None;
serialPort1.DataBits = 8;
serialPort1.StopBits = StopBits.One;
serialPort1.Handshake = Handshake.None;
serialPort1.Open();
serialPort1.Write("XXXX\r");
serialPort1.Close();
}
}
}
希望有帮助