我正在尝试将现有的一组功能从另一个应用程序移植到新应用程序向导中的操作栏/滑动格式。
我有单独的片段布局(除了名称之外都是相同的)并且包含所有按钮并且所有通过 toast 语句工作(和测试)。
我似乎不能做的是更新当前片段的文本视图。我已经尝试了我能想到的一切。我无法决定是否需要进行片段交易,或者我是否遗漏了一些小东西并追逐自己的尾巴。我头晕了,有人能阻止这个旋转木马吗?
这是片段编码的一部分
public static class DetailFragment extends Fragment {
public static final String ARG_SECTION_NUMBER = "section_number";
LayoutInflater _inflater;
ViewGroup _container;
public DetailFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
int position;
_inflater = inflater;
_container = container;
position = getArguments().getInt(ARG_SECTION_NUMBER)-1;
View rootView;
TextView dummyTextView;
// Location Database Handler
//LocationDatabaseHandler locationDatabaseHandler = new LocationDatabaseHandler(getActivity());
switch (position){
case 0:
rootView = inflater.inflate(R.layout.fragment_main_player,container, false);
dummyTextView= (TextView) rootView .findViewById(R.id.section_label);
// Player
Button btnTruncateDBPlayerTable = (Button) rootView.findViewById(R.id.btnTruncateDBPlayerTable);
Button btnPlayerCount = (Button) rootView.findViewById(R.id.btnPlayerCount);
Button btnShowDBPlayerList = (Button) rootView.findViewById(R.id.btnShowDBPlayerList);
Button btnShowPlayer = (Button) rootView.findViewById(R.id.btnShowPlayer);
Button btnAddContacts = (Button) rootView.findViewById(R.id.btnAddContacts);
Button btnAddContact = (Button) rootView.findViewById(R.id.btnAddContact);
btnTruncateDBPlayerTable.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Activity activity = getActivity();
//android.app.FragmentManager fm = getActivity().getFragmentManager();
////DummySectionFragment currFragment = (DummySectionFragment) fm.findFragmentById(R.id.fragment_main_player);
//View x = _inflater.inflate(R.layout.fragment_main_player, _container , false);
//v = _inflater.inflate(R.layout.fragment_main_player, _container , false);
//TextView myTextView = (TextView) x .findViewById(R.id.section_label);
if (activity != null) {
Toast.makeText(activity, "toast_you_just_clicked_a_fragment btnTruncateDBPlayerTable button", Toast.LENGTH_LONG).show();
DetailFragment updateFragment = dFragmentList.get(0);
//updateFragment.recieveUpdate("Holy Crap Batman");
//myTextView.append("WHOOT");
}
}
});
btnPlayerCount.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Activity activity = getActivity();
if (activity != null) {
Toast.makeText(activity, "toast_you_just_clicked_a_fragment btnPlayerCount button", Toast.LENGTH_LONG).show();
}
}
});
btnShowDBPlayerList.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Activity activity = getActivity();
if (activity != null) {
Toast.makeText(activity, "toast_you_just_clicked_a_fragment btnShowDBPlayerList button", Toast.LENGTH_LONG).show();
}
}
});
btnShowPlayer.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Activity activity = getActivity();
if (activity != null) {
Toast.makeText(activity, "toast_you_just_clicked_a_fragment btnShowPlayer button", Toast.LENGTH_LONG).show();
}
}
});
btnAddContacts.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Activity activity = getActivity();
if (activity != null) {
Toast.makeText(activity, "toast_you_just_clicked_a_fragment btnAddContacts button", Toast.LENGTH_LONG).show();
}
}
});
btnAddContact.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Activity activity = getActivity();
if (activity != null) {
Toast.makeText(activity, "toast_you_just_clicked_a_fragment btnAddContact button", Toast.LENGTH_LONG).show();
}
}
});
break;