Question

I have a listview that contain several EditTexts created dynamically according to the number of elements in listview.The items in listview are filled by data from server. With each edit text, there is a 'add' button in each row in that same listview. What i want is ,when the user inputs some number in those edit text boxes and click on 'add' button, the numbers input should be stored in some array in the order of clicking(first input in first position of array).The data is for future use to show input numbers in a seperate listview. In my code,when i input some number in edit text box and click 'add' only the first input works.In next clicks,nothing works(toast is shown here)..pls help..You may edit the code.Thanks in advance.(what i want is to store all those inputs, its user's choice to input in selected boxes only)

public void Addcart(View v)
{

try{    final EditText editnum= (EditText) findViewById(R.id.edittext); 

View.OnClickListener handler = new View.OnClickListener(){
    public void onClick(View v) {   
        if(v.getId()==R.id.addbutton)
        { //  switch (v.getId()){
      //  case R.id.addbutton:
            Toast.makeText(getBaseContext(), 
                    "Input: " + editnum.getText().toString(), 
                    Toast.LENGTH_SHORT).show();
           //   break;
        }
    }
};

findViewById(R.id.addbutton).setOnClickListener(handler);
}
catch(Exception e){
    Log.e("Android Edit Text Example", e.toString());

}

Was it helpful?

Solution

I think if you have created class which extends BaseAdapter. which does work of rendering view of list inside getView() method. So, you can easily get the position of that list row (getView(int ) argument is position your rendering) and also inside it you can create and your edittext dynamically also add button setting listeners.

now you can get position of row your clicking by using onItemclickListener() for that list returns the position of row hit by user,

so in on Addbutton click you can create Vector and insert that entered element in vector at specified index by using it's method.

so, next time you render new list you can use this vector as list to pass as data of numbers.

hope explanation works for you ..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top