Мне не удается установить видимость текстового вида VISIBLE.GONE в моем фрагменте.TextView setVisibility не работает в ViewPager Fragment
Мой макет фрагмент:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="b5.project.medibro.fragments.PrescriptionsFragment">
<ListView
android:layout_width="match_parent"
android:id="@+id/prescriptions_list"
android:layout_height="wrap_content" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_input_add" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/noItems"
android:textSize="18sp"
android:textColor="@color/myPrimaryColor"
android:layout_gravity="center"
android:text="@string/no_medi_items" />
</FrameLayout>
Я инстанцирован в TextView правильно, но не в состоянии отладки кода. Любые предложения по этой проблеме? Мой фрагмент кода Java является
public class PrescriptionsFragment extends Fragment {
private static final String TAG = PrescriptionsFragment.class.getSimpleName();
FloatingActionButton fab;
ListView prescriptionsList;
private OnFragmentInteractionListener mListener;
private ArrayList<Medication> medications;
TextView tv;
public PrescriptionsFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_prescriptions, container, false);
tv = (TextView) v.findViewById(R.id.noItems);
tv.setVisibility(View.GONE);
fab = (FloatingActionButton) v.findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getActivity(), AddPrescription.class));
}
});
medications = new ArrayList<>();
DatabaseHandler db = new DatabaseHandler(getActivity());
HashMap<Integer, Medication> hashMap = db.getMedicationDetails();
if (hashMap.isEmpty()) {
tv.setVisibility(View.VISIBLE);
} else {
Log.d(TAG, "hashmap size: " + hashMap.size());
tv.setVisibility(View.GONE);
for (int i = 0; i < hashMap.size(); i++) {
medications.add(i, hashMap.get(i));
}
prescriptionsList = (ListView) v.findViewById(R.id.prescriptions_list);
prescriptionsList.setAdapter(new MyMedAdapter(getActivity(), "all", medications));
}
return v;
}
}
Мой LogCat сниппет:
03-31 11:33:03.986: D/Database Handler(13900): selectQuery: SELECT * FROM medication
03-31 11:33:03.987: D/Database Handler(13900): Fetching: Test1
03-31 11:33:03.987: D/PrescriptionsFragment(13900): hashmap size: 1
03-31 11:33:03.988: D/FeedFragment(13900): onResume
Может кто-нибудь сказать, что случилось с этим кодом?
проверки 'если (hashMap.isEmpty()) {}' в коде это было бы Пусто или нет –
Нет его нет. Я проверил журналы. Лог-кошка отображает размер hasmap. –
вы забыли сделать объект hashmap –