我有一个带参数化构造函数和ArrayList作为参数的类。 ArrayList的大小在构造函数上有效,但onCreate
方法的大小为零。怎么可能?
public class ViewDetail extends AppCompatActivity {
private static final String TAG = "val";
final String POSITION_CLICKED="position";
private ArrayList<DataModel> mData=new ArrayList<>();
private Context mC;
public ViewDetail( Context c,ArrayList<DataModel> data) {
this.mData = data;
this.mC = c;
Log.v(TAG,"MDATA SIZE "+mData.size());
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_detail);
Log.v(TAG,"MDATA SIZE2 "+ mData.size());
short pos = 0;
try {
pos = getIntent().getExtras().getShort(POSITION_CLICKED);
} catch (Exception e) {
e.printStackTrace();
}
}}
答案 0 :(得分:0)
public ViewDetail( Context c,ArrayList<DataModel> data) {
this.mData = data;
this.mC = c;
Log.v(TAG,"MDATA SIZE "+mData.size());
}
错误!! ...不要创建扩展Activity
的该类的构造函数。
您可以通过
传递该数据,而不是上述内容Intent