如何从片段移动到活动
现在我在片段活动。现在我想从片段去活动。 这是我的代码告诉我?如何从片段移动到活动
public class People extends BaseFragment implements OnClickListener {
static String name;
ListView listview;
TextView et;
public static String username;
static public List<SuccessStoreyItem> success_list3 = new ArrayList<SuccessStoreyItem>();
public static int people_index ;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View view= inflater.inflate(R.layout.home,null);
ParserResult pr = new ParserResult();
Button b=(Button) view.findViewById(R.id.home1);
listview = (ListView)view.findViewById(R.id.lv_home);
et=(TextView) view.findViewById(R.id.editText1);
b.setOnClickListener(this);
if(ParserResult.success_list2.size() != 0){
success_list3 = ParserResult.success_list2;
}
listview.setAdapter(new Adapters(success_list3 ,MainActivity.mainactivity_context));
ParserResult.success_list2 = new ArrayList<SuccessStoreyItem>();
listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
// Toast.makeText(getActivity(), "fuck you", Toast.LENGTH_LONG).show();
Profile frg3 = new Profile();
Bundle b3 = new Bundle();
username = "";
username = success_list3.get(position).getStorey_id();
Intent i = new Intent(MainActivity.mainactivity_context,Profile_otheruser.class);
startActivity(i);
// b3.putString("username", username);
// b3.putInt("index_people", position);
people_index = position;
frg3.setArguments(b3);
// ((MainActivity)getActivity()).launchNewFragment(frg3, R.id.tab2);
// Toast.makeText(getActivity(), "Name :"+name ,1).show();
}
});
return view;
}
public void onListItemClick(ListView l, View v, int position, long id) {
//Do your stuff..
}
@Override
public void onResume() {
// TODO Auto-generated method stub
super.onResume();
setTitle(R.string.Home);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
name=et.getText().toString();
Bundle bundle = new Bundle();
bundle.putString("Name", name);
Toast.makeText(getActivity(), "Name :"+name ,1).show();
//((MainActivity)getActivity()).launchNewFragment(new Home2(),R.id.tab1);
}
}
文字是: 告诉我,我说我的方法(背景下,activity.class),开始活动(I)类方法是正确的?
Fragment包含一个接口。活动实现接口。通过这种方式,片段可以与任何数量的实现该接口的活动一起使用。
public class SettingMap extends Fragment implements OnCheckedChangeListener,
android.widget.CompoundButton.OnCheckedChangeListener {
public interface BestRidesSettingsDialogListener {
// change the map type
void onMapSettingsChange(int mapType);
}
某处片段安全检查活动已实现的接口,然后在活动执行代码
Activity a = getActivity();
BestRidesSettingsDialogListener activity = (BestRidesSettingsDialogListener.class.isAssignableFrom(a
.getClass())) ? (BestRidesSettingsDialogListener) a : null;
if (activity != null) {
activity.onMapSettingsChange(mapType);
}
活动实现了接口
public class KmlReader extends ActionBarActivity implements
BestRidesFollowDialogListener {
@Override
public void onMapSettingsChange(int mapType) {
if (mMap != null) {
mMap.setMapType(mapType);
}
}
你知道关于fragmentpager,pageradapter吗? – 2015-05-15 16:20:08
是的,我有一个关于onActivityResult的fragmentpager适配器的提示。 http://*.com/questions/6147884/onactivityresult-not-being-called-in-fragment/27087414#27087414 – danny117 2015-05-21 12:43:04
是什么问题你面对? – Apoorv 2014-08-28 14:16:12
您可能想知道Android中的活动和片段是什么,它们是如何相关的,并在提出这些问题之前与其他人合并。 http://developer.android.com/guide/components/fragments.html – 2014-08-28 14:39:09
你可能想要在这里重复的问题上多次执行代码。但我已经在下面回答了。 – danny117 2014-08-28 18:45:37