如何把群众演员不同的活动? [英] How to put Extras to different activity?

查看:157
本文介绍了如何把群众演员不同的活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有3个活动。我还用Tab键主机单独活动时,切换标签小部件。

For example, i have 3 activities.. I also use Tab host with separate activity when switch tab widget.

1) FoodTypeListActivity.class :有食物类型的列表,即早餐,晚餐,午餐..

1) FoodTypeListActivity.class:there is a list of food type i.e. Breakfast, Dinner, Lunch..

2) MainTabActivity.class :Tabhost其中有3片部件

2) MainTabActivity.class : Tabhost which has 3 tab widget

3) FoodListActivity.class :这个活动是标签控件之一

3) FoodListActivity.class : this activity is one of tab widget

我在 MainTabActivity.class 的布局headlabel它会显示食物的TextView的类型从previous活动( FoodTypeListActivity。类

I have a headlabel in layout of MainTabActivity.class which will show type of food as Textview from the previous activity(FoodTypeListActivity.class)

的问题是; 我想送类型食品的名称( FoodTypeListActivity.class )设置为headlabel中( MainTabActivity.class ),并送食物类型(<$ C $编号C> FoodTypeListActivity.class )至( FoodListActivity。类

The problem is; i want to send the name of type of food from (FoodTypeListActivity.class) to set as headlabel in (MainTabActivity.class) and send id of food type (FoodTypeListActivity.class) to (FoodListActivity.class)

我如何实施putExtra将数据发送到不同的活动在 FoodTypeListActivity.class

How do i implement putExtra to send data to different activity in on ListItem click of FoodTypeListActivity.class

现在我有以下code在 FoodTypeListActivity.class

Now i have the the following code in FoodTypeListActivity.class

lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,int position, long id) {


              if(position==0){
                Intent i = new Intent(FoodTypeListActivity.this, MainTabActivity.class);  

                i.putExtra("foodTypeID", 3);
                i.putExtra("foodTypeName", "Breakfast");
                startActivity(i);

              } 

            }
          });

感谢您

推荐答案

您应该只使用共享preference。

You should just use shared preference.

在您的列表视图中单击使用此把价值共享preference。

In your listview click use this to put the values in shared preference.

  SharedPreferences items = getSharedPreferences("my_food_data", 0);
  SharedPreferences.Editor editor = settings.edit();
  editor.putInt("foodTypeID", 3);
  editor.putString("foodTypeName", "Breakfast"); 
  editor.commit(); //VERY important

现在拉出来的数据在任何活动中使用。

Now to pull the data out in ANY activity use..

   SharedPreferences items = getSharedPreferences("my_food_data", 0);
   int foodId = settings.getInt("foodTypeId", 0);
   String foodTitle = items.getString("foodTypeName", "No Name"); //the default value of of "no name will be used if nothing is in the preference file.

我觉得这很适合你正在尝试做的。

I think this works well for what you are trying to do.

这篇关于如何把群众演员不同的活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆