Почему мои текстовые представления не отображаются, я вижу их в окне предварительного просмотра в моем XML-файле, но не в моем приложении? (Android) - PullRequest
0 голосов
/ 03 июля 2018

Текстовое представление отображается в окне предварительного просмотра кода, но не при запуске приложения. У меня была эта проблема для другой страницы, и я не могу ее решить. Я не совсем уверен, почему это происходит. Я играл с множеством разных вещей в коде, и, похоже, ни одна из них не работает.

Ниже приведен код моего файла XML и моей деятельности:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">



<TextView
    android:id="@+id/provider_title"
    android:layout_width="match_parent"
    android:layout_below="@id/moreInfoPicture"
    android:layout_height="30dp"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="5dp"
    android:layout_marginRight="0dp"
    android:layout_marginLeft="25dp"
    />

<TextView
    android:id="@+id/about_the_provider"
    android:layout_width="match_parent"
    android:layout_below="@id/provider_title"
    android:layout_height="30dp"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="5dp"
    android:layout_marginRight="0dp"
    android:layout_marginLeft="25dp"
    android:text="About the provider"
    />

<TextView
    android:id="@+id/more_info_text"
    android:layout_width="match_parent"
    android:layout_below="@id/about_the_provider"
    android:layout_height="250dp"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="5dp"
    android:layout_marginLeft="25dp"
    />



  <ImageButton
    android:id="@+id/moreInfoPicture"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:layout_alignParentEnd="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="0dp"
    android:padding="0dp"

    />




</RelativeLayout>
</ScrollView>

Вот код моей деятельности:

 package com.example.leoconnelly.connexus;

import android.content.Context;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.method.ScrollingMovementMethod;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.ArrayList;

/**
 * Created by leoconnelly on 4/11/18.
 */

public class MoreInfoActivity extends AppCompatActivity {
    ImageButton moreInfoImage;
    TextView moreInfoText;
    TextView AboutProv;
    TextView ProvName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.more_info);

       Context mContext = this;

        Typeface buttonFont = Typeface.createFromAsset(this.getAssets(),  "fonts/Roboto-Regular.ttf");
        Typeface boldFont = Typeface.createFromAsset(this.getAssets(),  "fonts/Roboto-Bold.ttf");

        AboutProv = findViewById(R.id.about_the_provider);
        AboutProv.setTypeface(boldFont);
        AboutProv.setTextColor(000000);
        AboutProv.setText("About the provider:");
        AboutProv.setTextSize(30);

        ProvName = findViewById(R.id.provider_title);
        ProvName.setTypeface(boldFont);
        ProvName.setTextColor(000000);



        // moreInfoImage.findViewById(R.id.moreInfoPicture);
        moreInfoText = findViewById(R.id.more_info_text);
       // moreInfoImage = findViewById(R.id.moreInfoPicture);

//get array

        final ArrayList<HealthCenterButton> healthCentersList = HealthCenterButton.getHealthCentersFromFile("healthCenters.json", this);
        final ArrayList <String> miniList = new ArrayList <String>();


        for (HealthCenterButton healthCenterButton : healthCentersList) {
            miniList.add(healthCenterButton.mini);
           System.out.println("BEEEP BEEP BEEP BOOP BOP BEEPED BOOP BEEP");
            System.out.println(miniList);
       }



       //set up array for mini iamges







        /*
        ImageView iw= (ImageView)findViewById(R.id.imageView1);

         */


        //make it scrollable
        moreInfoText.setMovementMethod(new ScrollingMovementMethod());

       // int index = getIntent(index);

        int index = getIntent().getExtras().getInt("index");

        //String intentStringNumber = getIntent().getStringExtra("index");

//        int index = Integer.parseInt(intentStringNumber);

      // int index = 0;

        System.out.println(index +" BOOOP BOP BOOP BOOP BOPP BOOP");

        if (index == 7) {
            //Bowdoin

            moreInfoText.setText("Founded in Boston's Dorchester neighborhood in 1972 by community residents, " +
                    "Bowdoin Street Health Center remains focused on providing outstanding medical care while" +
                    " maintaining a tradition of working with residents to identify and meet their " +
                    "unique health needs. The mission of the health center is to provide excellent, " +
                    "compassionate care to our patients and support the health of the entire community.");
            //Picasso.with(mContext).load(miniList.get(1)).into(moreInfoImage);
           // moreInfoImage =
            //        Picasso.with(mContext).load(healthCenterButton.imageUrl).into(thumbnailImageView);

          // ProvName.setText("Bowdoin Street Health Center");
            AboutProv.setText("About the provider:");



        }

        else  if (index == 7) {
            //BIDMC Chelsea

            moreInfoText.setText("In the midst of a thriving Chelsea neighborhood, " +
                    "we bring world-class health care to patients north of Boston. " +
                    "Our patients have the best of all worlds: dedicated staff, the atmosphere of a private practice, " +
                    "and access to the expertise, resources, and systems of Beth Israel Deaconess Medical Center.");

           // ProvName.setText("BIDMC Chelsea");
        }

        else  if (index == 2) {
            //BIDMC
            moreInfoText.setText("Beth Israel Deaconess Medical Center (BIDMC) in Boston, Massachusetts is a teaching hospital of Harvard Medical School. It was formed out of the 1996 merger of Beth Israel Hospital (founded in 1916) and New England Deaconess Hospital (founded in 1896). Among independent teaching hospitals, Beth Israel Deaconess Medical Center consistently ranks in the top three recipients of biomedical research funding from the National Institutes of Health. Research funding totals nearly $200 million annually. BIDMC researchers run more than 850 active sponsored projects and 200 clinical trials. " +
                    "The Harvard-Thorndike General Clinical Research Center, " +
                    "the oldest clinical research laboratory in the United States, " +
                    "has been located on this site since 1973");
           // ProvName.setText("Beth Israel Deaconess Medical Center (BIDMC)");


        }

        else  if (index == 1) {
            //Dimock Community Health Center Complex
            moreInfoText.setText("Recognized nationally as a model for the delivery of comprehensive health and human services in an urban community, The Dimock Center provides the residents of Boston with convenient access to high quality, low cost health care and human services that might not otherwise be available to the communities we serve. " +
                    " In 2013, Dimock handled over 76,000 visits annually with 17,000 unique patients and " +
                    "clients representing a wide range of socioeconomic and ethnic backgrounds.");

            //ProvName.setText("Dimock Community Health Center");


        }

        else  if (index == 4) {
            //Fenway Health
            moreInfoText.setText("For more than forty years, " +
                    "Fenway Health has been working to make life healthier for the people in our neighborhood, " +
                    "the LGBT community, people living with HIV/AIDS and the broader population. Fenway was " +
                    "founded in 1971 as part of the free clinic movement by students who believed that" +
                    " ''health care should be a right, not a privilege. In its early days, " +
                    "Fenway was a drop-in clinic providing free blood pressure checks and STD screenings. Over the years, Fenway obtained permanent space and incorporated as a freestanding health center with a staff of one volunteer doctor, one nurse and one intake worker. Today, Fenway Health has a budget of more than $90 million, a staff of 500 and a patient population of more than 28,000. " +
                    "Fenway Health is a Federally Qualified Community Health Center.");
          //  ProvName.setText("Fenway Health");

    }

    else  if (index == 5) {
        //South Cove Medical Center

        moreInfoText.setText("South Cove Community Health Center ('South Cove') is the premier Asian community health center of Massachusetts. Founded in 1972, South Cove provides medical and behavioral health services and youth and family programs for approximately 32,000 clients at four locations in the greater Boston area. Our mission is to improve the health and well being of all medically underserved in Massachusetts, with a special focus on Asian Americans.  " +
                "This mission is accomplished by providing high quality, " +
                "community-based health care and health promotion programs " +
                "that are accessible and linguistically and culturally competent for these populations.");
       // ProvName.setText("South Cove Medical Center");

    }

    else  if (index == 6) {
        //South Cove Chinatown
        moreInfoText.setText("South Cove Community Health Center ('South Cove') is the" +
                " premier Asian community health center of Massachusetts. 
  Founded in 1972, South Cove provides medical and" +
                " behavioral health services and youth and family programs for 
  approximately 32,000 clients at four locations in the greater Boston area. " +
                "Our mission is to improve the health and well being of all 
 medically underserved in Massachusetts, with a special focus on Asian 
  Americans. " +
                " This mission is accomplished by providing high quality," +
                " community-based health care and health promotion programs" +
                " that are accessible and " +
                "linguistically and culturally competent for these 
     populations");
      //  ProvName.setText("South Cove China Town");



    }




}
}

Ответы [ 3 ]

0 голосов
/ 03 июля 2018

Попробуйте ниже:

text.setTextColor(Color.parseColor(Color.BLACK));

или

text.setTextColor(Color.parseColor("#FFFFFF"));

вместо

ProvName.setTextColor(000000);
0 голосов
/ 03 июля 2018

Попробуйте:

public ImageButton moreInfoImage;
public TextView moreInfoText;
public TextView AboutProv;
public TextView ProvName;

или

public ImageButton moreInfoImage;
public TextView moreInfoText, AboutProv, ProvName;

Вы определяете TextViews в защищенном и специфичном для класса методе. Это вызывает проблемы с отображением действия вне метода onCreate.

Также вам следует избегать использования заглавной буквы в качестве первой буквы в вашей переменной. Это не правильные методики охоты на верблюдов.

Для ясности я бы изменил:

  • ПроПров о ПроПров
  • ProvName для provName

везде упоминается в вашем коде.

0 голосов
/ 03 июля 2018

ПОПРОБУЙТЕ

 <ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent">

Я пытался, но кажется, что прокрутка накладывается на макет, попробуйте это и дайте мне знать

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...