我的textview显示在代码预览中,但是当我运行该应用程序时却不显示。我在另一个页面上遇到了这个问题,无法解决。我不太确定为什么会这样。我一直在代码中处理许多不同的事情,但似乎都没有。
下面是我的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");
}
}
}
答案 0 :(得分:0)
请尝试
<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">
我尝试过,但似乎您的滚动视图覆盖了布局,请尝试此操作并让我知道
答案 1 :(得分:0)
尝试以下方法:
text.setTextColor(Color.parseColor(Color.BLACK));
或
text.setTextColor(Color.parseColor("#FFFFFF"));
代替
ProvName.setTextColor(000000);
答案 2 :(得分:-1)
尝试:
public ImageButton moreInfoImage;
public TextView moreInfoText;
public TextView AboutProv;
public TextView ProvName;
或
public ImageButton moreInfoImage;
public TextView moreInfoText, AboutProv, ProvName;
您可以使用受保护且特定于类的方法定义TextView。这会导致在onCreate方法之外显示活动的问题。
此外,您应该避免在变量中使用大写字母作为第一个字母。那不是正确的骆驼装箱方法。
为清楚起见,我将更改:
代码中提到的所有地方。