saveBtnYes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
saveBtnYesFunc(currentYesBtnId);
tempActivityList =activityNames;
return activityNames;
}
});
当我调用saveBtnYesFunc
函数时,它向onClick线程返回一个名为activityNames
的ArrayList值。我想将该值从onClickListener
方法内部传递给其父方法(此代码包含在另一个方法中)。代码return activityNames
的最后一行不起作用。
还有其他方法吗?
答案 0 :(得分:0)
您需要确定谁真正有兴趣查看此新列表。假设感兴趣的部分是某个类ListUsingClass的实例,这应该可以工作。
final ListUsingClass listUser = new ListUsingClass(); // or assign to existing reference
saveBtnYes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listUser.setActivityNames(saveBtnYesFunc(currentYesBtnId));
}
});
答案 1 :(得分:0)
您的问题还不清楚,我想您希望单击Button
时将Array
(activityNames
)保存在某处。
如果我理解得很好,您可以通过这种方式进行:
class YourClass { //almost surely it extends Activity (or AppCompatActivity)
private List<String> thePlaceWhereTheArrayWillBeLocated = new ArrayList<String>(); //You should define a class varibale where the result of saveBtnYesFunc will ends up (I think that the content is of String type)
... onCreate(...) {
super.onCreate(savedInstanceState);
...
...
saveBtnYes.setOnClickListener(new View.OnClickListener() { //I don't know if it's inside the onCreate, but it could be here
@Override
public void onClick(View v) {
thePlaceWhereTheArrayWillBeLocated = saveBtnYesFunc(currentYesBtnId); //Maybe some type casts are needed
//tempActivityList =activityNames;
//return activityNames; //This line is totally incorrect
}
});
}
void wheneverFunctionYouWant() {
//do whatever you want with thePlaceWhereTheArrayWillBeLocated
}
}