how to get editable changed value from edittext in android

Go To StackoverFlow.com

0

i am fetching text from mysql server database in customized ListView. In customized list view i append all text to edittext. how to get edittext value and store it on textview while content of edittext is changed. i want changed edittext values please help me

        Main.java(here i can pass json array as constructor to EditMainMenulistview.java)
        JSONArray json = jArray.getJSONArray("mainmenu");
        list=(ListView)findViewById(R.id.mainmenulist);
         adapter=new MainMenulist(this, json);
         list.setAdapter(adapter);

here i can place button update//button in Main.java

EditMainMenulistview.java

    public class EditMainMenulistview extends BaseAdapter {
protected static Context Context = null;
int i;
public String editnewmainmenu, menuname,edittext;
String qrimage;
Bitmap bmp, resizedbitmap;
Bitmap[] bmps;
Activity activity = null;
private LayoutInflater inflater;

private ImageView[] mImages;
String[] itemimage;
TextView[] tv;
String itemname, itemcode;
public String[] itemnames, itemcodes;
HashMap<String, String> map = new HashMap<String, String>();

public EditMainMenulistview(Context context, JSONArray imageArrayJson) {
    Context = context;
    // inflater =
    // (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    // imageLoader=new ImageLoader(activity);
    inflater = LayoutInflater.from(context);
    this.mImages = new ImageView[imageArrayJson.length()];
    this.bmps = new Bitmap[imageArrayJson.length()];
    this.itemnames = new String[imageArrayJson.length()];
    this.itemcodes = new String[imageArrayJson.length()];

    try {

        for (i = 0; i < imageArrayJson.length(); i++) {
            JSONObject image = imageArrayJson.getJSONObject(i);
            qrimage = image.getString("menuimage");
            itemname = image.getString("menuname");
            itemcode = image.getString("menucode");
            itemnames[i] = itemname;
            itemcodes[i] = itemcode;

            byte[] qrimageBytes = Base64.decode(qrimage.getBytes());

            bmp = BitmapFactory.decodeByteArray(qrimageBytes, 0,
                    qrimageBytes.length);
            int width = 100;
            int height = 100;
            resizedbitmap = Bitmap.createScaledBitmap(bmp, width, height,
                    true);
            bmps[i] = bmp;

            mImages[i] = new ImageView(context);
            mImages[i].setImageBitmap(resizedbitmap);

            mImages[i].setScaleType(ImageView.ScaleType.FIT_START);

            // tv[i].setText(itemname);
        }
        System.out.println(itemnames[i]);
        System.out.println(map);

    } catch (Exception e) {
        // TODO: handle exception
    }
}

public int getCount() {
    return mImages.length;
}

public Object getItem(int position) {
    return position;
}

public long getItemId(int position) {
    return position;
}

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

    View vi = convertView;

    vi = inflater.inflate(R.layout.editmainmenulist, null);

    EditText text = (EditText) vi.findViewById(R.id.editmaimenu);
    ImageView image = (ImageView) vi.findViewById(R.id.menuimage);


    image.setImageBitmap(bmps[position]);

    text.append(itemnames[position]);
     edittext = text.getText().toString();
    System.out.println(edittext);
    //Toast.makeText(Context, edittext, Toast.LENGTH_LONG).show();

    return vi;

}

}

what i am changed text in EditMaiMenulisview i click button(Update) Main.java i want print what i have been changed in Edittext. please replay

2012-04-04 04:39
by Vinoth
see http://www.andreabaccega.com/blog/2010/10/09/onchange-event-on-edittext-in-android - ngesh 2012-04-04 04:42
can u write piece of code according to the my question. pleas - Vinoth 2012-04-04 04:45
@Vinoth : Well that is your work, our work is to simple GUIDE - Bhavin 2012-04-04 04:49
i never use edittext changed events let u given code for me means really help for learnin - Vinoth 2012-04-04 05:00
do you mean that each item in the listView also have a textView - Mark Pazon 2012-04-04 05:04
ya sir each item in a lisview also have textview. i can append with edit text.please replay for my questio - Vinoth 2012-04-04 05:07


0

Please use the following code

public View getView(final int position, View convertView, ViewGroup parent) {
    View vi = convertView;
    if(vi == null) {

         vi = inflater.inflate(R.layout.editmainmenulist, null);
    }

    EditText text = (EditText) vi.findViewById(R.id.editmaimenu);
    ImageView image = (ImageView) vi.findViewById(R.id.menuimage);
    TextView tv = (TextView) vi.findViewById(R.id.<textViewId>); //replace with  
                                                                  //textView ID

    image.setImageBitmap(bmps[position]);

    text.append(itemnames[position]);
     edittext = text.getText().toString();
text.addTextChangedListener(new TextWatcher() {

    public void afterTextChanged(Editable s) {
         Log.v("LOG","After text change value "+s.toString());
    }

    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

    }

});
     System.out.println(edittext);
        //Toast.makeText(Context, edittext, Toast.LENGTH_LONG).show();
     tv.setText(edittext);
   return vi;
}

You can get the value in afterTextChange method

2012-04-04 05:53
by Jitendra
edittext.addTextChangedListener(new TextWatcher() this line shows following error. please tell me how to solve Multiple markers at this line - TextWatcher cannot be resolved to a type - The method addTextChangedListener(new TextWatcher(){}) is undefined for the type Strin - Vinoth 2012-04-04 06:15
I have edit my code.please have a loo - Jitendra 2012-04-04 06:17
This is helping for you - Jitendra 2012-04-04 06:30
in this line s.getText().toString(). shows as error .you want type cast.. what can i d - Vinoth 2012-04-04 06:41
i am getting after text changes.. thanks for spending time for m - Vinoth 2012-04-04 06:53


0

change getView to:

public View getView(final int position, View convertView, ViewGroup parent) {
    View vi = convertView;
    if(vi == null) {

         vi = inflater.inflate(R.layout.editmainmenulist, null);
    }

    EditText text = (EditText) vi.findViewById(R.id.editmaimenu);
    ImageView image = (ImageView) vi.findViewById(R.id.menuimage);
    TextView tv = (TextView) vi.findViewById(R.id.<textViewId>); //replace with  
                                                                  //textView ID

    image.setImageBitmap(bmps[position]);

    text.append(itemnames[position]);
     edittext = text.getText().toString();
    System.out.println(edittext);
    //Toast.makeText(Context, edittext, Toast.LENGTH_LONG).show();

    tv.setText(edittext);


    return vi;

}

if some of the items in your listview changed you should call adapter.notifyDataSetChanged();

2012-04-04 05:08
by Mark Pazon
i tried the out put screen displays text and editext . i don't want text.what are the itemnames are there every thing append to editext . eg:itemnames are comes x,y from database i append x,y to edittext. now i am changed x,y to a,b in edit text .now i want a,b values ..are u understand my proble - Vinoth 2012-04-04 05:25
if some of the elements changed, you should call adapter.notifyDataSetChanged() so the new data could reflect to the listvie - Mark Pazon 2012-04-04 10:51
Ads