2017-01-31 8 views
0

ボタンの背景リソースを変更するたびに、別のボタンが最初のボタンの外観を模倣するように、ボタンのバックグラウンドリソースを模倣するボタンの背景リソースを変更する方法を知りたいと思います。 。例えば他のボタンの背景リソースを模倣するボタンを設定する方法

int icon = R.drawable.ic_icon; //more specifically I stored R.drawable.ic_icon in SQL and retrieve and save in int icon when retrieve from that table, so when the table is change the first button dynamically change on create; 
btn_01.setBackgroundResource(icon); //when this button is pressed it inflates a layout containing btn_02 
btn_02.setBackgrounResource(??????); //this button is on a different layout and is used by different activity and should take the backgroundresource of the button that have been pressed to call that layout. 

else文が、私は2番目のボタンでコピーする別のボタンがあり、各ボタンが異なるbackgroundresourceの可能性を持っている場合、私は使用することができます。私はここにとにかく完全にあなたの質問を理解したができなかった

答えて

0

は、私はあなたがBtn_01がクリックされたときに活動を開始する前にテントにリソースIDを置くことができます

得たものです。

Btn_01.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Intent intent = new Intent(this,Activity2.class); 
      intent.putExtra("resource_key", R.drawable.ic_heart); 
      startActivity(intent); 
     } 
    }); 

、あなたのActivity2にあなたは自分のリソースデータを取得することができ、あなたが

int DEFAULT_RESOURCE = R.drawable.ic_close; 
    int resourceId = getIntent().getIntExtra("resource_key",DEFAULT_RESOURCE); 
    Btn_02.setBackgroundResource(resourceId); 
を好きなボタンに設定します
関連する問題