package com.example.ops.testapplication; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.Button; public class MainActivity extends AppCompatActivity { private Button Button1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); findViews(); } private void findViews(){ find_Simp(R.id.button1); } private void find_Simp(int v){ find(Button1,v); setPic(Button1); } private void find(Button b, int v){ b = (Button) findViewById(v); } private void setPic(Button b){ b.setBackgroundResource(R.drawable.pic1_1_1); } }
解决方案
40
找到问题所在了
private Button Button1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); findViews(); } private void findViews(){ find_Simp(R.id.button1); } private void find_Simp(int v){ find(Button1,v); } private void find(Button b, int v){ b = (Button) findViewById(v); b.setBackgroundResource(R.drawable.pic1_1_1); } }
这样写就没问题说了你再另一方法里找到的button 和外面的button不是一个 java传值问题