开发者

Android get different content in single activity

actually I'm searching a way to show d开发者_如何学Cifferent content in one activity everytime when it's created.Here is what actually I'm thinking to do but not really sure if there is a way and how can I do it. Basically I have two activities. The first one contains a listview with 100 elements on it.I want to be able to show different content in activity 2 when I click a listview item in Activity 1. I need to be able to change two textviews and one imageview.

Any suggestions how can I do that? Thanks in advance!


You want to use Intents to pass Payload between your Activitys.

On Activty1 you make a new Intent like:

Intent myIntent = new Intent(view.getContext(),
Activty2.class);
myIntent.putExtra("detailtext", ((TextView) view).getText());
startActivityForResult(myIntent, 0);

the putExtra Method is for your Payload.

then in Activty2 you can extract the Intent with:

getIntent().getStringExtra("detailtext"));

hope that helps


Do somethins like this :

Activity 1:

Intent intent = new Intent(Activity1.this, Activity2.class);
intent.putExtra("someKey","someValue");
startActivityForResult(Intent, 0);

Activity 2:

String i = getIntent().getStringExtra("someKey"));
TextView txt = (TextView) findViewById(R.id.textView); //your textview's id
txt.setText(i);

That should work!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜