您好我是新来的Android编程安卓:按钮点击后的错误传输数据
我试图创造一种,用户点击第一 页按钮,在按钮改变文字颜色的应用颜色和更改反映在另一个活动页面中。
为此,我有 1)一个片段类(BookLockerFragment),其参照包含按钮 2)父活动文件(TabActivity.java) 3)的活性文件以反映变化的XML文件( complainResponse.java)
下面是代码: LodgeComplaintFragment.java发生在这条线
ArrayList<String>userSelectedOptions = new ArrayList<String>();
if(btnSis.getCurrentTextColor()==Color.BLUE){
userSelectedOptions.add("SIS");
}
Button but = (Button) root.findViewById(R.id.searchButton);
.....
but.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
buttonListener.onMakeBookingButtonPressed(userSelectedOptions);
}
});
TabMainActivity.java
public void onMakeBookingButtonPressed(ArrayList<String> list) {
// TODO Auto-generated method stub
Intent intent = new Intent(TabMainActivity.this,
complainResponse.class);
intent.putStringArrayListExtra("userSelectOptions",list);
startActivity(intent);
}
complainResponse.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the message from the intent
Intent intent = getIntent();
setContentView(R.layout.complainresponse);
userInput = intent.getStringArrayListExtra("userSelectOptions");
// Creates the window used for the UI
if (userInput != null) {
if (userInput.get(0) != null) {
textview1 = (TextView) findViewById(R.id.textView1);
textview1.setText(userInput.get(0));
}
}
}
错误: 如果(userInput = NULL){ complainResponse.j的//! AVA
的logcat: java.lang.IndexOutOfBoundsException
请帮
了大部分的代码已经被省略以允许相关的多个 – user2445971
你从来没有把任何东西在列表中。 – hichris123