我正在android studio中创建一个android应用程序,我需要将字符串数组从一个类传递到另一个类。 它似乎没有工作思想,我找不到什么是错的。 我试图用构造函数来完成它。Java,试图将字符串数组从一个类传递到另一个
我会省略不必要的代码。
class MyFragment extends Fragment{
//I create a string array to pass on the other class
public String likeTitles[] ={"mazda","whynot","OHYEAAAaa","ok","1983198312893"};
public MainFragment(String s1[]){
s1= likeTitles;
}
}
public class List extends ListActivity{
String myStringArr[]=new String[5];
MainFragment myFrag = new MainFragment(myStringArr);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getListView().getContext(), android.R.layout.simple_list_item_1, myStingArr);
getListView().setAdapter(adapter);
}
我试图使用类的字符串数组,它适用于我的适配器,但这是行不通的。
这不是你如何通过片段和活动之间的数据。只需在这里做一个简单的搜索,即“在活动之间传递数据”,您就会发现需要了解的一切。标记为dupe http://stackoverflow.com/questions/5194548/how-to-pass-data-between-fragments – NoChinDeluxe
[如何在片段之间传递数据]的可能重复(http://stackoverflow.com/questions/ 5194548/how-to-pass-data-between-fragments) – NoChinDeluxe