android bundle传递参数,android – 使用bundle将数据从一个活动传递...

我目前正在尝试通过REST API调用获取数据,解析它以获取我需要的信息,然后将该信息传递给新活动.我正在使用loopj.com中的异步HTTP客户端作为REST客户端,然后分别使用以下代码将onClick和onCreate用于当前和未来的活动.

Eclipse没有为我的任何代码传递任何错误,但是当我尝试在模拟器中运行时,在新活动/视图打开时我什么也得不到(即空白屏幕).我试图在我的REST CLIENT中使用不同的URL进行编码,但我仍然没有看到任何内容.我甚至通过在onClick中注释try / catch并更改bundle.putString(“VENUE_NAME”,venueName)中的venueName来取消API调用. to searchTerm.仍然,新视图出现但没有显示任何内容.什么没有通过,或者我忘记了第二个活动显示的是什么名字?

public void onClick(View view) {

Intent i = new Intent(this, ResultsView.class);

EditText editText = (EditText) findViewById(R.id.edit_message);

String searchTerm = editText.getText().toString();

//call the getFactualResults method

try {

getFactualResults(searchTerm);

} catch (JSONException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

//Create the bundle

Bundle bundle = new Bundle();

//Add your data from getFactualResults method to bundle

bundle.putString("VENUE_NAME", venueName);

//Add the bundle to the intent

i.putExtras(bundle);

//Fire the second activity

startActivity(i);

}

第二个活动中应该接收意图和捆绑并显示它的方法:

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

//Get the message from the intent

//Intent intent = getIntent();

//String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

//Get the bundle

Bundle bundle = getIntent().getExtras();

//Extract the data…

String venName = bundle.getString(MainActivity.VENUE_NAME);

//Create the text view

TextView textView = new TextView(this);

textView.setTextSize(40);

textView.setText(venName);

//set the text view as the activity layout

setContentView(textView);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {

getActionBar().setDisplayHomeAsUpEnabled(true);

}

}

谢谢你的帮助.非常感谢.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值