两个活动,在Android中为null

时间:2012-08-21 07:53:51

标签: android android-layout

我有两个活动:一个是actionbar,其中我有一些ImageViews,另一个是从第一个扩展的类。在第二个活动中,我想从第一个活动中更改一些Imagesviews的图标。这个有可能。

当我尝试:

check_box_list_view = (ImageView) findViewById(R.id.email_list_item_checkbox_icon);

我得到了空。如何在第二个活动中访问第一个活动的ImageResoure图像?

ActionBarVCard:

public class ActionBarVCard extends Activity{
    private ImageView action_bar_home_icon, action_bar_title_icon, action_bar_vCard_icon;
    private TextView action_bar_title_text;
    private RelativeLayout relative;
    private ActionBar action;
    private RelativeLayout.LayoutParams params;

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        params = new RelativeLayout.LayoutParams(android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT,android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);
        action = getActionBar();
        relative = new RelativeLayout(getApplicationContext());
        action_bar_home_icon = new ImageView(getApplicationContext());
        action_bar_vCard_icon = new ImageView(getApplicationContext());
        action_bar_title_icon = new ImageView(getApplicationContext());
        action_bar_title_text = new TextView(getApplicationContext());

        action_bar_home_icon.setImageResource(R.drawable.home_android);
        params.setMargins(20, 0, 20, 0);
        action_bar_home_icon.setLayoutParams(params);
        action_bar_home_icon.setId(1);
        action_bar_home_icon.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                Intent intent = new Intent(ActionBarVCard.this, MainActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                intent.putExtra("ClassName", "action_bar_coverView_icon");
                startActivity(intent);              
            }
        });

        params = new RelativeLayout.LayoutParams(android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT,android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.RIGHT_OF, action_bar_home_icon.getId());
        params.setMargins(0, 10, 5, 0);
        action_bar_title_icon.setImageResource(R.drawable.twoarrows_icon);
        action_bar_title_icon.setLayoutParams(params);
        action_bar_title_icon.setId(2);

        params = new RelativeLayout.LayoutParams(android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT,android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.RIGHT_OF, action_bar_title_icon.getId());
        action_bar_title_text.setText("vCard");
        action_bar_title_text.setTextSize(24);
        action_bar_title_text.setLayoutParams(params);
        action_bar_title_text.setId(3);

        params = new RelativeLayout.LayoutParams(android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT,android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        params.setMargins(0, 0, 20, 0);
        action_bar_vCard_icon.setImageResource(R.drawable.installvcard_selected_android);
        action_bar_vCard_icon.setLayoutParams(params);
        action_bar_vCard_icon.setId(4);

        action.setDisplayShowCustomEnabled(true);
        action.setDisplayShowHomeEnabled(false);
        action.setDisplayShowTitleEnabled(false);

        relative.addView(action_bar_home_icon);
        relative.addView(action_bar_title_icon);
        relative.addView(action_bar_title_text);
        relative.addView(action_bar_vCard_icon);
        relative.setGravity(Gravity.CENTER);
        action.setCustomView(relative);

        return true;
    }
}

电子名片:

public class vCard_view extends ActionBarVCard{
    Button speichernButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);

         requestWindowFeature(Window.FEATURE_ACTION_BAR);
         setTheme(R.style.mytheme);
         setContentView(R.layout.vcard_view);
         speichernButton = (Button) findViewById(R.id.speichern_button);
         speichernButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

}

我想在vCard类中更改icon_bar_home_icon的图标,但我不知道如何

0 个答案:

没有答案