Set dynamically created TextView on frame layout

Akshay

I want to pass some data from one activity to another and set it in dynamically created TextView over frame layout of that activity..I'm using intent for that but at second activity the data is not getting extracted..Can any one tell me the simple way for this.. Following is my code..

Hidden.java

public class Hidden extends Activity implements OnClickListener {
Button btnnameadd, btnnameremove, btnmobileadd, btnmobileremove, btndone;
EditText etname, etmobile;
ImageView ivlogo;
private AlertDialog dialog;
private Uri mImageCaptureUri;
Intent jump;
//options for image selection
private static final int PICK_FROM_CAMERA = 1;
private static final int CROP_FROM_CAMERA = 2;
private static final int PICK_FROM_FILE = 3;
LinearLayout llname, llmobile, llimage;


@Override
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.hidden);
        captureImageInitialization();

        init();

}

private void init() {
    etname=(EditText)findViewById(R.id.editTextname);
    etmobile=(EditText)findViewById(R.id.editTextmobile);
    btnnameadd=(Button)findViewById(R.id.buttonnameadd);
    btnnameremove=(Button)findViewById(R.id.buttonnameremove);
    btnmobileadd=(Button)findViewById(R.id.buttonmobileadd);
    btnmobileremove=(Button)findViewById(R.id.buttonmobileremove);
    btndone=(Button)findViewById(R.id.buttondone);
    llname=(LinearLayout)findViewById(R.id.name);
    llmobile=(LinearLayout)findViewById(R.id.mobile);
    btnnameadd.setOnClickListener(this);
    btnnameadd.setOnClickListener(this);
    btnnameremove.setOnClickListener(this);
    btnmobileadd.setOnClickListener(this);
    btnmobileremove.setOnClickListener(this);
    btndone.setOnClickListener(this);

}

@Override
public void onClick(View v) {
    jump=new Intent(Hidden.this,Framelayout.class);
    if(v.getId()==R.id.buttonnameadd)
    {
        String strname=etname.getText().toString();
        Log.d("Log",strname);
        jump.putExtra("Name",strname);
    }else if(v.getId()==R.id.buttonnameremove)
    {
        btnnameremove.setEnabled(false);
        llname.removeView(findViewById(R.id.editTextname));
    }else if(v.getId()==R.id.buttonmobileadd)
    {
        String strmobile=etmobile.getText().toString();
        Log.d("Log",strmobile);
        jump.putExtra("Mobile",strmobile);
        Log.d("LOG",jump.putExtra("Mobile",strmobile).toString());
    }else if(v.getId()==R.id.buttonmobileremove)
    {
        llmobile.removeView(findViewById(R.id.editTextmobile));         
    }else if(v.getId()==R.id.buttondone)
    {
        Log.d("LOG","1");
        startActivity(jump);
    }
}

}

FrameLayout.java

public class Framelayout extends Activity implements OnClickListener {
FrameLayout frameLayout;
Button b2,b3;
//private ProgressDialog pDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_framelayout);
    frameLayout = (FrameLayout)findViewById(R.id.f1);
     b2=(Button)findViewById(R.id.button2);
     b3=(Button)findViewById(R.id.buttonload);
 b2.setOnClickListener(this);
     b3.setOnClickListener(this);

  }
public void onClick(View v) {
     if(v.getId()==R.id.button2){
        Intent i=new Intent(Framelayout.this,Hidden.class);
        startActivity(i);
    }else if(v.getId()==R.id.buttonload){
        Log.d("Log",getIntent().getStringExtra("Name"));
         editframelayout();
    }
}

private void editframelayout() {
    String name=getIntent().getExtras().getString("Name");
    String mobile=getIntent().getExtras().getString("Mobile");
    TextView tvname=new TextView(this);
    tvname.setText(name);
    tvname.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    tvname.setGravity(Gravity.CENTER);
    TextView tvmobile=new TextView(this);
    tvmobile.setText(mobile);
    tvmobile.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    tvmobile.setGravity(Gravity.CENTER);
    frameLayout.addView(tvname);
    frameLayout.addView(tvmobile);
}

}

Saro Taşciyan

You must use one of putExtra() overloaded methods of the intent instance you created to add your data.

Here is a sample:

Intent intent = new Intent(this, SignoutActivity.class); // # this parameter is the context of the caller
intent.putExtra("PARAM_TEXTBOX_TEXT", textboxText);
startActivity(intent);

Edit for the code you added, your design is very poor and doesn't accomplish what is intended.

Every time you click a Button a new instance of Intent is created. you are calling startActivity() only in single case:

else if(v.getId()==R.id.buttondone)
{
    Log.d("LOG","1");
    startActivity(jump);
}

Now you assume that the parameters added in previous button clicks are still there, but they aren't. When you click buttondone you create a new instance of Intent with no extras at all.

You can work this around as follows:

...
else if(v.getId()==R.id.buttondone)
{
    String strname = etname.getText().toString();
    if (strname != null && !strname.equals(""))
    {
        jump.putExtra("Name",strname);                
    }

    String strmobile = etmobile.getText().toString();
    if (strmobile != null && !strmobile.equals(""))
    {
        jump.putExtra("Mobile",strmobile);            
    }

    startActivity(jump);
}

It still isn't well structured, but might do the trick for you

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to create a pagination for dynamically created table layout using set visible?

From Dev

set Width dynamically of textview

From Dev

set Width dynamically of textview

From Dev

Add a TextView dynamically in a layout ANDROID

From Dev

How to open dynamically created layout?

From Dev

Set layout params dynamically

From Dev

Set layout params dynamically

From Dev

How to Dynamically set text to TextView?

From Dev

Adding a textview and imageview to a linearlayout created dynamically in android

From Dev

How to get the text onClick on a TextView that is created dynamically?

From Dev

Getting value from dynamically created textview in android

From Dev

Getting value from dynamically created textview in android

From Dev

Set .attr to dynamically created button

From Dev

Set the position of a dynamically created button

From Dev

how to handle dynamically created textview seprately in TextView Array?

From Dev

how to set frame dynamically in swift?

From Dev

Android: Set textcolor for programmatically created TextView

From Dev

Android: Set textcolor for programmatically created TextView

From Dev

Programmatically set layout_toLeftOf and layout_below for TextView

From Dev

How to set layout_toEndOf and layout_toRightOf programmatically in textview

From Dev

finding width of textView before it is drawn when it is created dynamically

From Dev

How to auto increase Height of Dynamically created TextView in android?

From Dev

How to auto increase Height of Dynamically created TextView in android?

From Dev

How to set background color to a dynamically created view?

From Dev

set attribute for dynamically created class not working in javascript

From Dev

Android set style attribute to dynamically created ImageView

From Dev

Dynamically created collapsible-set in jQuery Mobile

From Dev

Set onclick handler to dynamically created button

From Dev

How to set different events for dynamically created element

Related Related

  1. 1

    How to create a pagination for dynamically created table layout using set visible?

  2. 2

    set Width dynamically of textview

  3. 3

    set Width dynamically of textview

  4. 4

    Add a TextView dynamically in a layout ANDROID

  5. 5

    How to open dynamically created layout?

  6. 6

    Set layout params dynamically

  7. 7

    Set layout params dynamically

  8. 8

    How to Dynamically set text to TextView?

  9. 9

    Adding a textview and imageview to a linearlayout created dynamically in android

  10. 10

    How to get the text onClick on a TextView that is created dynamically?

  11. 11

    Getting value from dynamically created textview in android

  12. 12

    Getting value from dynamically created textview in android

  13. 13

    Set .attr to dynamically created button

  14. 14

    Set the position of a dynamically created button

  15. 15

    how to handle dynamically created textview seprately in TextView Array?

  16. 16

    how to set frame dynamically in swift?

  17. 17

    Android: Set textcolor for programmatically created TextView

  18. 18

    Android: Set textcolor for programmatically created TextView

  19. 19

    Programmatically set layout_toLeftOf and layout_below for TextView

  20. 20

    How to set layout_toEndOf and layout_toRightOf programmatically in textview

  21. 21

    finding width of textView before it is drawn when it is created dynamically

  22. 22

    How to auto increase Height of Dynamically created TextView in android?

  23. 23

    How to auto increase Height of Dynamically created TextView in android?

  24. 24

    How to set background color to a dynamically created view?

  25. 25

    set attribute for dynamically created class not working in javascript

  26. 26

    Android set style attribute to dynamically created ImageView

  27. 27

    Dynamically created collapsible-set in jQuery Mobile

  28. 28

    Set onclick handler to dynamically created button

  29. 29

    How to set different events for dynamically created element

HotTag

Archive