2013-08-23 44 views
0

我想在当前活动中按下按钮时更改下一活动的背景&我有32个按钮,所有活动都会进行相同的活动但我想根据按钮prees所以它会改变32次我试试这个改变它的回地面,但它不工作当我按下当前活动中的按钮时如何更改下一个活动背景

buttons[0].setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       Intent myIntent = new Intent(Sori.this,listnameseries.class); 
       myIntent.putExtra("namemovies","fattetl3bet"); 
       startActivity(myIntent); 
       buttons[0].setBackgroundResource(R.drawable.back1); 


      } 
    }); 

    buttons[1].setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       Intent myIntent = new Intent(Sori.this,listnameseries.class); 
       myIntent.putExtra("namemovies","sikkarwasat"); 
       startActivity(myIntent); 
       buttons[0].setBackgroundResource(R.drawable.back254); 


      } 
    }); 

    buttons[2].setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       Intent myIntent = new Intent(Sori.this,listnameseries.class); 
       myIntent.putExtra("namemovies","superfamily"); 
       startActivity(myIntent); 
       buttons[0].setBackgroundResource(R.drawable.back2978); 


      } 
    }); 

    buttons[3].setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       Intent myIntent = new Intent(Sori.this,listnameseries.class); 
       myIntent.putExtra("namemovies","wiladaminalkhasira1"); 
       startActivity(myIntent); 
       buttons[0].setBackgroundResource(R.drawable.back27); 


      } 
    }); 

    buttons[4].setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       Intent myIntent = new Intent(Sori.this,listnameseries.class); 
       myIntent.putExtra("namemovies","wiladaminalkhasira2"); 
       startActivity(myIntent); 
       buttons[0].setBackgroundResource(R.drawable.back280); 


      } 
    }); 

    buttons[5].setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       Intent myIntent = new Intent(Sori.this,listnameseries.class); 
       myIntent.putExtra("namemovies","wiladaminalkhasira3"); 
       startActivity(myIntent); 
       buttons[0].setBackgroundResource(R.drawable.back278); 
       } 
    }); 

    buttons[6].setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       Intent myIntent = new Intent(Sori.this,listnameseries.class); 
       myIntent.putExtra("namemovies","zamanlbarghout1"); 
       startActivity(myIntent); 
       buttons[0].setBackgroundResource(R.drawable.back278); 
       } 
    }); 

    buttons[7].setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       Intent myIntent = new Intent(Sori.this,listnameseries.class); 
       myIntent.putExtra("namemovies","zamanlbarghout2"); 
       startActivity(myIntent); 
       buttons[0].setBackgroundResource(R.drawable.back278); 
       } 
    }); 

    buttons[8].setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       Intent myIntent = new Intent(Sori.this,listnameseries.class); 
       myIntent.putExtra("namemovies","ta7ounalchar1"); 
       startActivity(myIntent); 
       buttons[0].setBackgroundResource(R.drawable.back2896); 
       } 
    }); 

    buttons[9].setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       Intent myIntent = new Intent(Sori.this,listnameseries.class); 
       myIntent.putExtra("namemovies","ta7ounalchar2"); 
       startActivity(myIntent); 
       buttons[0].setBackgroundResource(R.drawable.back287); 
       } 
    }); 

    buttons[10].setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       Intent myIntent = new Intent(Sori.this,listnameseries.class); 
       myIntent.putExtra("namemovies","sar5troo7"); 
       startActivity(myIntent); 
       buttons[0].setBackgroundResource(R.drawable.back2879); 
       } 
    }); 
    buttons[11].setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       Intent myIntent = new Intent(Sori.this,listnameseries.class); 
       myIntent.putExtra("namemovies","sabaya1"); 
       startActivity(myIntent); 
       buttons[0].setBackgroundResource(R.drawable.back2789); 
       } 
    }); 
    buttons[12].setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       Intent myIntent = new Intent(Sori.this,listnameseries.class); 
       myIntent.putExtra("namemovies","sabaya2"); 
       startActivity(myIntent); 
       buttons[0].setBackgroundResource(R.drawable.back234); 
       } 
    }); 
    buttons[13].setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       Intent myIntent = new Intent(Sori.this,listnameseries.class); 
       myIntent.putExtra("namemovies","sabaya3"); 
       startActivity(myIntent); 
       buttons[0].setBackgroundResource(R.drawable.back2435); 
       } 
    }); 
    buttons[14].setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       Intent myIntent = new Intent(Sori.this,listnameseries.class); 
       myIntent.putExtra("namemovies","sabaya4"); 
       startActivity(myIntent); 
       buttons[0].setBackgroundResource(R.drawable.back2345); 
       } 
    }); 
    buttons[15].setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       Intent myIntent = new Intent(Sori.this,listnameseries.class); 
       myIntent.putExtra("namemovies","sabaya5"); 
       startActivity(myIntent); 
       buttons[0].setBackgroundResource(R.drawable.back2435); 
       } 
    }); 
    buttons[16].setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       Intent myIntent = new Intent(Sori.this,listnameseries.class); 
       myIntent.putExtra("namemovies","sana3oud"); 
       startActivity(myIntent); 
       buttons[0].setBackgroundResource(R.drawable.back2345); 
       } 
    }); 
    buttons[17].setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       Intent myIntent = new Intent(Sori.this,listnameseries.class); 
       myIntent.putExtra("namemovies","ta7tasama2alwatan"); 
       startActivity(myIntent); 
       buttons[0].setBackgroundResource(R.drawable.back2435); 
       } 
    }); 
    buttons[18].setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       Intent myIntent = new Intent(Sori.this,listnameseries.class); 
       myIntent.putExtra("namemovies","natrin"); 
       startActivity(myIntent); 
       buttons[0].setBackgroundResource(R.drawable.back26546); 
       } 
    }); 
    buttons[19].setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       Intent myIntent = new Intent(Sori.this,listnameseries.class); 
       myIntent.putExtra("namemovies","7oudoudchakika"); 
       startActivity(myIntent); 
       buttons[0].setBackgroundResource(R.drawable.back2546); 
       } 
    }); 
    buttons[20].setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       Intent myIntent = new Intent(Sori.this,listnameseries.class); 
       myIntent.putExtra("namemovies","yasmin3atik"); 
       startActivity(myIntent); 
       buttons[0].setBackgroundResource(R.drawable.back2546); 
       } 
    }); 
    buttons[21].setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       Intent myIntent = new Intent(Sori.this,listnameseries.class); 
       myIntent.putExtra("namemovies","znoodelset"); 
       startActivity(myIntent); 
       buttons[0].setBackgroundResource(R.drawable.back2546); 
       } 
    }); 
    buttons[22].setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 

       Intent myIntent = new Intent(Sori.this,listnameseries.class); 
       myIntent.putExtra("namemovies","l3btmoot"); 
       startActivity(myIntent); 
       buttons[0].setBackgroundResource(R.drawable.back25464); 
       } 
    }); 
+0

你为什么要设置按钮的背景资源[0 ]如果您需要更改“Sori”实例的背景资源?为什么不使用myIntent.putExtra发送颜色,然后在活动初始​​化时处理它? –

回答

1

中的onCreate添加额外给你的意图,例如资源ID

myIntent.putExtra("resource_id", R.color.myPreferedBackground); 

然后在接下来的活动():

int bg = getIntent.getIntExtra("resource_id"); 
myLayout.setBackgroundResource(bg); 
+0

resourse id为背景或活动? – DoctorDoom

+0

我的布局是什么?????? – DoctorDoom

+0

myLayout是您的活动的环绕布局。 – dumazy

0

随着意图发送关于颜色下一个活动的信息。

在下一个活动onCreate基于信息更改颜色。

+0

我可以想像op正在期待你会是谁! – ChiefTwoPencils

相关问题