Search code examples
androidlistviewandroid-edittextlistadaptersimpleadapter

How to get edittext position in Listview


I am working on ListView having EditText inside.I have used four EditText in each item of ListView.I am facing problem with getting the position of EditText in the ListView. Below is my code. I am able to fetch the position of TextView,but while fetching the position of EditText I am facing problem.

           lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {


                    myproductpercarton = (TextView) view.findViewById(R.id.txtorderamount);
                    final String ssss =(String) ((TextView) view.findViewById(R.id.txtorderamount)).getText();             
                    mytotalprice = (TextView) view.findViewById(R.id.txtprice);
                    mm = (CheckBox) view.findViewById(R.id.mycheck);
                    mm.setFocusableInTouchMode(true);
                    mm.setFocusable(true);
                    mm2 = (CheckBox) view.findViewById(R.id.mynewcheck);
                    mm2.setFocusableInTouchMode(true);
                    mm2.setFocusable(true);
                    myorderprice = (EditText) view.findViewById(R.id.txtorderby);
                    myorderprice.setFocusableInTouchMode(true);
                    myorderprice.setFocusable(true);
                    mycartonno = (EditText) view.findViewById(R.id.txtordercarton);
                    mycartonno.setFocusableInTouchMode(true);
                    mycartonno.setFocusable(true);


                    myproductno = (EditText) view.findViewById(R.id.txtproduct);
                    myproductno.setFocusableInTouchMode(true);
                    myproductno.setFocusable(true);

                    myproductno.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {


                            String myprodpercart;
                            map = (HashMap<String, String>) getListView().getItemAtPosition(position);
                            HashMap<String, String> map2 = (HashMap<String, String>) getListView().getItemAtPosition(position);
                            HashMap<String, String> map3 = (HashMap<String, String>) getListView().getItemAtPosition(position);


                            double orderId4;
                            double mycarton2;
                            double mynewcart;
                            double myprodno2;
                            double mycartquantity;
                            double mytotal;
                            String mynoocarton;
                            double mynoocarton44;
                            int myprodno3;                           
                            String temp=mycartonno.getText().toString();
                            String contents = mycartonno.getText().toString();
                            orderId4 = new Double(map.get(TAG_PRODUCTPERCARTON));
                            Log.d("MyOrderId :: ", String.valueOf(orderId4));
                            mycartonprice2 = map.get(TAG_PRODUCTPERCARTON2);
                            Log.d("MyCartonPrice :: ", String.valueOf(mycartonprice2));                             
                            mynoocarton = mycartonno.getText().toString();
                            mynoocarton44 = new Double(mycartonno.getText().toString());

                            mycarton2 = new Double(mynoocarton);
                            mynewcart = new Double(mycartonprice2);
                            myprodno2 = new Double(orderId4 * mycarton2);
                            myprodno3 = new Integer((int) myprodno2);
                            mycartquantity = new Double(mycartonno.getText().toString());
                            Log.d("MyCartonNo :: ", mycartonno.getText().toString());
                            Log.d("MyCartonNo2 :: ",contents);                            
                            mytotal = new Double(mycartquantity * mynewcart);
                            String mynoocarton3 = String.valueOf(mynoocarton44);                               
                            String total = String.valueOf(mytotal);
                            String mm = String.valueOf(myprodno3);                             
                            mycartonno.setText(mynoocarton3);
                            myproductno.setText(mm);
                            mytotalprice.setText(total);
                            Toast.makeText(getActivity(), ssss + " " + mynewcart + "----" + mm + "  " + total,
                                    Toast.LENGTH_SHORT).show();

                        }
                    });
                    mydiscount = (EditText) view.findViewById(R.id.txtdiscount);
                    mydiscount.setFocusableInTouchMode(true);
                    mydiscount.setFocusable(true);
                }
            });

Solution

  • I solved this issue by myself and now its working fine. I just have taken another textview and two new edittext inside setOnClickListener. I just added below code inside setOnClickListener.

    TextView mynewtotal = (TextView) view.findViewById(R.id.txtprice);
    EditText mycartonprod = (EditText) view.findViewById(R.id.txtordercarton);
    mycartonprod.setFocusableInTouchMode(true);
    mycartonprod.setFocusable(true);
    EditText myprod = (EditText) view.findViewById(R.id.txtproduct);
    myprod.setFocusableInTouchMode(true);
    myprod.setFocusable(true);