2014-10-16 74 views
0

我想從動態創建bean的每個視圖中獲取editext值和位圖圖像。我沒有得到如何使用它。我試圖從視圖vx.But中獲取細節這沒有發生,這是我的代碼。從視圖中獲取編輯文本值

請幫助...

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); 
     }}); 


} 

}

+1

'((EditText上)vx.findViewById(R.id.textout))的getText()'? – prettyvoid 2014-10-16 21:05:45

+0

是的,你是絕對正確的。你能幫助如何從imageview獲取位圖嗎? – Soham 2014-10-16 21:10:20

+0

你可以點擊答案併發布你的答案,所以我可以接受它。 – Soham 2014-10-16 21:17:41

回答

0

用於檢索的文本:

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

確保將「toString()」添加到最後以獲取字符串值。 – naweinberger 2014-10-16 21:47:44

0

我張貼的答案,因爲我還沒有得到有關如何獲得imagebitmap答案。此代碼工作

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

很高興你知道了。祝你好運 – prettyvoid 2014-10-16 21:25:32

相關問題