2014-09-19 62 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接口應該很容易。

相關問題