我想從動態創建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);
}});
}
}
'((EditText上)vx.findViewById(R.id.textout))的getText()'? – prettyvoid 2014-10-16 21:05:45
是的,你是絕對正確的。你能幫助如何從imageview獲取位圖嗎? – Soham 2014-10-16 21:10:20
你可以點擊答案併發布你的答案,所以我可以接受它。 – Soham 2014-10-16 21:17:41