2014-09-19 70 views
1


我有一个活动,用户可以在对话框中输入一个名称。
然后,一个包含带有输入名称和Edittext的textview的'BoardElemnt'对象(它是我自己的类扩展一个LinearLayout)将动态添加到Activity中。用户可以根据需要经常这样做。

如果用户长时间点击这样的BoardElement,他可以选择是否要编辑或删除此BoardElement。
如果他想编辑这个BoardElement,应该显示一个新的活动,用户可以从这个特定的BoardElement编辑一些东西。 我的问题是,我不能将这个BoardElement对象传递给'EditActivity'。

我BoardElement类:
传递一个自定义对象,将LinearLayout扩展到另一个活动

public class BoardElement extends LinearLayout implements TextWatcher{ 

private static Context context; 
private RelativeLayout parentLayout ; 
private LinearLayout fBoard ; 
private TextView txtOutput ; 
private EditText editBudget ; 
private String fName; 
private TextView txtfName= new TextView(getContext()) ; 
private EditText editBetrag = new EditText(getContext()) ; 


///////////////////////////////////////// 
// 
// This Data can be Edited in the EditActivity 
// 

private String fotoPath ; 
private String note ; 
private String name ; 
private String category ; 
private String store ; 
private String measures ; 


// 
// 
///////////////////////////////////////// 

/** 
* 
* @param context 
* @param _parentLayout 
* @param _furnitureName 
*/ 
public BoardElement(Context _context, RelativeLayout _parentLayout, String _fName){ 
    super(_context); 

    context = _context; 
    parentLayout = _parentLayout ; 
    fName= _fName; 


    category = fName; 



    LinearLayout.LayoutParams mparams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 
    mparams.setMargins(0, 0, 0, 10) ; 
    this.setLayoutParams(mparams) ; 
    this.setOrientation(LinearLayout.HORIZONTAL) ; 
    this.setBackgroundResource(R.drawable.board_element) ; 



    LinearLayout.LayoutParams txtParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.MATCH_PARENT) ; 
    txtParams.gravity = Gravity.CENTER ; 
    txtParams.weight = 1.0f; 
    txtFurnitureName.setLayoutParams(txtParams) ; 
    txtFurnitureName.setBackgroundResource(R.drawable.txt_fName) ; 
    txtFurnitureName.setText(this.fName) ; 
    txtFurnitureName.setTextColor(getResources().getColor(R.color.white)) ; 
    txtFurnitureName.setTextSize(20) ; 
    this.addView(txtfName) ; 





    editBetrag.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL) ; 
    editBetrag.setTextColor(getResources().getColor(R.color.white)) ; 
    editBetrag.setGravity(Gravity.RIGHT) ; 
    editBetrag.setBackgroundResource(R.drawable.input_field); 
    editBetrag.setFilters(new InputFilter[] {new InputFilter.LengthFilter(9)}) ; 
    this.addView(editBetrag) ; 
    editBetrag.addTextChangedListener(this) ;  


} 
//////////////////////////////// 
// 
// getters and setters 

// ... 



我尝试没有成功它SerializableParcelable传递到其他活动。我只是得到我的字符串成员与Parcelable方法传递,但后来我不能编辑这些成员...

问候

回答

0

你可以单独的类分为两个不同的人。一个仅包含可以编辑的字符串属性(Properties.class)的类。另一种只是构建布局(Layout.class)。这样,您只需通过Intent将Properties.class发送给您的EditActivity,并在您要膨胀时将其传递给Layout.class。要实现Properties.class的Parcelable接口应该很容易。

相关问题