我有一个ListView,其中每行都包含一个EditText场和TextView的,什么都我在EDITTEXT我想在TextView中看到类型? [英] I have a ListView, where each row contains an EditText field and textview, what ever i typed in the Edittext i want to see in the textview?

查看:194
本文介绍了我有一个ListView,其中每行都包含一个EditText场和TextView的,什么都我在EDITTEXT我想在TextView中看到类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里,我有以下以下code: -

Here i have the following code below :-

public class OrderActivity extends ListActivity implements OnClickListener{

ArrayList<String> data,rate, num;
OrderAdapter orderAdapter;
int i = 0;
int s;
TextView tvNumber,tvName,tvRate;
EditText etQty,etRemarks;
Button sendToConfirm,edit,saveAndAdd;
//  EditText qty,remarks;
//OrderAdapter orderAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.order);
    Init();

下面我从previous活动的ArrayList

Here i get arraylists from previous activity

    Bundle extras = getIntent().getExtras(); 
    data = extras.getStringArrayList("list");
    rate = extras.getStringArrayList("rate");
    num = extras.getStringArrayList("number");
    for(String str : data)  {
        Log.d("data", str);

    }
    for(String str1 : rate) {
        Log.d("data", str1);
        //s = Integer.parseInt(st)

    }
    //Log.d("total", s);
    for(String strnum : num)    {
        Log.d("data", strnum);

    }


    String[] captionArray = (String[]) data.toArray(
            new String[data.size()]);

    orderAdapter = new OrderAdapter(
            OrderActivity.this, R.layout.order_list,
            captionArray);
    setListAdapter(orderAdapter);
    return ;
}

初​​始化按钮

public void Init() {
    sendToConfirm = (Button) findViewById(R.id.bsendtoconfirm);
    edit = (Button) findViewById(R.id.bEdit);
    saveAndAdd = (Button) findViewById(R.id.bsave);
    sendToConfirm.setOnClickListener(this);
    edit.setOnClickListener(this);
    saveAndAdd.setOnClickListener(this);
    //etQty.addTextChangedListener(this);
}

下面是baseAdapter类。

Here is the baseAdapter class.

private class OrderAdapter extends BaseAdapter {
    String[] items;

    public OrderAdapter(Context context, int textViewResourceId,
            String[] items) {
        this.items = items;
    } 


    public View getView(final int POSITION, View convertView,
            ViewGroup parent) {

        //          TextView tvNumber,tvName,tvRate;
        //          EditText etQty,etRemarks;

        View view = convertView;

        if (view == null) {
            LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = vi.inflate(R.layout.order_list, null);

        } 
        tvNumber = (TextView) view.findViewById(R.id.itemnumber);
        tvName = (TextView) view.findViewById(R.id.itemname);
        tvRate = (TextView) view.findViewById(R.id.itemrate);
        etQty = (EditText) view.findViewById(R.id.editqty);
        etRemarks = (EditText) view.findViewById(R.id.editremarks);
        etQty = (EditText) view.findViewById(R.id.editqty);
        //tvRate = (TextView) v.findViewById(R.id.itemrate);

Ontextchange监听器。在这里无论我在EditText上键入我需要在TextView中获得?请帮我出这一点。

Ontextchange listener . here whatever i type in the edittext i need to get in the textview ?please help me out with this.

        etQty.addTextChangedListener(new TextWatcher() {

            public void onTextChanged(CharSequence s, int start, int before, int count) {
                // TODO Auto-generated method stub

            }

            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
                // TODO Auto-generated method stub

            }

            public void afterTextChanged(Editable s) {
                // TODO Auto-generated method stub
                String text;
                text=etQty.getText().toString();
                if(text!=null)
                {
                    tvRate.setText(text);
                }
                else {
                    tvRate.setText("You Have Not type anything");
                }
            }
        });

        tvNumber.setText(num.get(POSITION));
        tvName.setText(data.get(POSITION));
        tvRate.setText(rate.get(POSITION));


        return view; 
    }


    public int getCount() {
        // TODO Auto-generated method stub
        return items.length;
    }


    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }


    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }
}
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.bsendtoconfirm:
        Log.d("click", "send");
        break;

    case R.id.bEdit:
        Log.d("click", "edit");
        break;
    case R.id.bsave:
        Log.d("click", "saved");
        finish();
        break;
    }
}
//  public void afterTextChanged(Editable s) {
//      // TODO Auto-generated method stub
////        String text;
////        text=etQty.getText().toString();
////        if(text!=null)
////        {
////        tvRate.setText(text);
////        }
////        else {
////        tvRate.setText("You Have Not type anything");
////        }
//  }
//  public void beforeTextChanged(CharSequence s, int start, int count,
//          int after) {
//      // TODO Auto-generated method stub
//
//  }
//  public void onTextChanged(CharSequence s, int start, int before, int count) {
//      // TODO Auto-generated method stub
//
//  }

}

推荐答案

您好,您可以使用下面的code要做到这一点,

hi you can use the code below to do this,

源:
https://dl.dropbox.com/u/68130108/ListViewEditItem.rar

public class OrderActivity extends ListActivity implements OnClickListener{
// create static object to hold your widget in listview
static TextView sTxt;
static EditText sEdTxt;
static int p;

.
.
.
.


etQty.setId(position);
etQty.setTag(tvRate);           
etQty.setOnFocusChangeListener(new OnFocusChangeListener() {

public void onFocusChange(View v, boolean hasFocus) {
    sPosition = v.getId();
    sTxt = (TextView) v.getTag();
    EditText e = ((EditText) v);
    if (!e.getText().toString().equals("")) {
        if (hasFocus) {
                // change your num arraylist values at the position
                // because you can’t save anything on ListView Item.
            num.set(sPosition,e.getText().toString());                          
        }                       
    }
}
});

editText.addTextChangedListener(new TextWatcher() {
   @Override
   public void onTextChanged(CharSequence s, int start,int before, int count) {}
   @Override
   public void beforeTextChanged(CharSequence s, int start,int count, int after) { }
   @Override
   public void afterTextChanged(Editable s) {
       // every text change setText of textview 
       sTxt.setText(s);
   }
});

tvRate.setText(num.get(position));
.
.
.
.

这篇关于我有一个ListView,其中每行都包含一个EditText场和TextView的,什么都我在EDITTEXT我想在TextView中看到类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆