简体   繁体   中英

get edit text value from view

I want to get the editext value and bitmap image from the every view that has bean created dynamically.I am not getting how to use it.I have tried to get the details from view vx.But it's not happening.Here is my code.

Please help...

public class MainActivity extends Activity {

EditText textIn;
Button buttonAdd;
LinearLayout container;
View addView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final ArrayList<String> value=new ArrayList<String>();
    textIn = (EditText)findViewById(R.id.textin);
    buttonAdd = (Button)findViewById(R.id.add);
   Button button = (Button)findViewById(R.id.all);
    container = (LinearLayout)findViewById(R.id.container);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            for (int i = 0, c = container.getChildCount(); i < c; i++) {

                View vx = container.getChildAt(i);

            }
        }
    });

    buttonAdd.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View arg0) {
            LayoutInflater layoutInflater = 
                    (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            addView = layoutInflater.inflate(R.layout.row, null);
            EditText textOut = (EditText)addView.findViewById(R.id.textout);
            textOut.setText(textIn.getText().toString());
            textOut.addTextChangedListener(new TextWatcher() {
                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {

                    // TODO Auto-generated method stub

                }

                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                    // TODO Auto-generated method stub
                }

                @Override
                public void afterTextChanged(Editable s) {



                }
            });
            final ImageView buttonimg = (ImageView)addView.findViewById(R.id.remove);
            buttonimg.setOnClickListener(new OnClickListener(){

                @Override
                public void onClick(View v) {
                    //((LinearLayout)addView.getParent()).removeView(addView);
                    buttonimg.setImageResource(R.drawable.logo);
                }});

            container.addView(addView);
        }});


}

}

I am posting the answer since I haven't got the answer about how to get the imagebitmap. This code is working

         ImageView v2=((ImageView) vx.findViewById(R.id.remove));
         Bitmap bm=((BitmapDrawable)v2.getDrawable()).getBitmap();

检索文本:

((EditText)vx.findViewById(R.id.textout)).getText()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM