开发者

Pass a string from a class to another

i have to pass a string from a class to another class. but i can't do it..

i try this:

public void onItemClick(AdapterView<?> parent, View view, int position, long arg3)
        {               
            Intent i = new Intent(Contas.this, Registros.class);                
            i.putExtra("valor", data.开发者_StackOverflow社区get(position).getDescricao_conta().toString());                
            startActivity(i);           
        }

in the class that receives the value i put this:

String descricao = getIntent().getExtras().getString("valor");

i have tree tabs each one with an activity, the activity's has listview's bounded with data. i want to click in an item from a list in the tab1, and then in tab2, i see in a list the settings from the item clicked in tab1. i already have the data base i only need to pass the string that i want froom a class to another.


This has worked for me and is a bit more simple:

String descricao = getIntent().getStringExtra("valor");


This might be a bit much depending on your needs, but you could store everything you want accessible from multiple activities in an application class. Just create a new class that extends android.app.Application and reference it in your AndroidManifest.xml like this:

<application android:name=".CustomApplicationClass" ... >
...activities here...
</application>

Then you can get a reference to it in each activity like this:

private CustomApplicationClass app = (CustomApplicationClass) getApplication();

I hope that helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜