Cannot setText to TextView in Android - android

I am having real problems trying to set a text to TextView on my android application. The string that I am trying to display was passed to another activity via an intent. I seem to have successfully retrieved this extra from the intent but i am failing to attach it to my TextView. Please can someone help? i am using fragments throughout.
All I am getting is my layout display without the Text that i am trying to assign.
Fragment:2
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.article_fragment, parent, false);
journalTitle = (String) getArguments().getString(EXTRA_JOURNALTITLE); // extra from intent
Log.d("onCreateView", "a.getJournalTitle: " + journalTitle); // this works. displays in logCat
journalTitleView = (TextView) v
.findViewById(R.id.journalTitle_articleFragment_textView);
journalTitleView.setText(journalTitle);
Layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/journalTitle_articleFragment_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:text="journal title"
android:textSize="12sp" />
<TextView
android:id="#+id/pubYear_articleFragment_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#id/journalTitle_articleFragment_textView"
android:text="pubYear"
android:textSize="12sp" />
<TextView
android:id="#+id/volume_articleFragment_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#id/pubYear_articleFragment_textView"
android:text="volume"
android:textSize="12sp" />
<TextView
android:id="#+id/issue_articleFragment_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_toRightOf="#id/volume_articleFragment_textView"
android:text="issue"
android:textSize="12sp" />
<TextView
android:id="#+id/pageInfo_articleFragment_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#id/issue_articleFragment_textView"
android:text="pageInfo"
android:textSize="12sp" />
<TextView
android:id="#+id/title_articleFragment_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/journalTitle_articleFragment_textView"
android:gravity="center"
android:layout_marginTop="25dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="article title"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/authorString_articleFragment_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/title_articleFragment_textView"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="authors"
android:textSize="12sp" />
<TextView
android:id="#+id/abstractText_articleFragment_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/authorString_articleFragment_textView"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="abstractText"
android:textSize="15sp" />

In onCreateView you should only inflate your layout and return it:
View v = inflater.inflate(R.layout.article_fragment, parent, false);
return v;
Your textView modifications should be moved to onViewCreated

Try :
TextView journalTitleView = (TextView) v.findViewById(R.id.journalTitle_articleFragment_textView);
journalTitleView.setText(journalTitle);

I think you should try this code :
public static void changeFragmentTextView(String s) {
Fragment frag = getFragmentManager().findFragmentById(R.id.yourFragment);
((TextView) frag.getView().findViewById(R.id.ournalTitle_articleFragment_textView)).setText(s);
}`

Related

How start New Activity when Click on Title Of HEADER_VIEW in RecyclerView To display items in IT

enter image description here
In Activty one i have RecyclerView with to View :
HEADER_VIEW
ITEM_VIEW
Header_view.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#FFF7F7F7">
<TextView
android:id="#+id/tv_group_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginStart="16dp"
android:layout_weight="1"
android:text="TextView"
android:textColor="#F50057"
android:textSize="20sp" />
<TextView
android:id="#+id/more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_weight="1"
android:text="More..." />
</RelativeLayout>
Item_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/ll_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/cv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:elevation="3dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:background="?attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:src="#mipmap/ic_launcher" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_below="#id/imageView"
android:background="#f5fff2">
<TextView
android:id="#+id/tv_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:text="name"
android:textAlignment="center"
android:textColor="#FF20C200"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/new_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/old_price"
android:layout_marginRight="5dp"
android:layout_marginStart="5dp"
android:layout_toEndOf="#+id/old_price"
android:text="480.00 DA"
android:textColor="#FF65C2FD"
android:textStyle="bold" />
<TextView
android:id="#+id/old_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#+id/tv_name"
android:layout_marginBottom="10dp"
android:layout_marginRight="5dp"
android:layout_marginStart="5dp"
android:text="250.00 DA"
android:textAlignment="center"
android:textColor="#F50057" />
<ImageButton
android:id="#+id/overflow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignTop="#+id/new_price"
android:layout_marginEnd="5dp"
android:layout_marginLeft="5dp"
android:background="?attr/selectableItemBackgroundBorderless"
app:srcCompat="#drawable/ic_more_vert_black_24dp" />
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
I created the Adapter and it Work Fine .
My problem is :
I need when I click on more TextView In HEADER_VIEW an New Activity Start
with Specific Itemes Of Stection.
My try :
In Adapter Exactly in onBindViewHolder
#Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
//Context context = mContextWeakReference.get();
if (mContext == null) {
return;
}
if (SECTION_VIEW == getItemViewType(position)) {
final SectionViewHolder sectionViewHolder =(SectionViewHolder)holder;
GroupTitleModel sectionItem = ((GroupTitleModel) mUsersAndSectionList.get(position));
sectionViewHolder.title.setText(sectionItem.title);
sectionViewHolder.more.setText(sectionItem.moreSection);
sectionViewHolder.more.setOnClickListener( new View.OnClickListener() {
#Override
public void onClick(View view) {
// I TRY TO DO IT HERE BUT NO THINGS
}
} );
return;
}
My first thought is that you are bringing yourself into trouble by doing it this way.
You separate the Header view and its Content view, so the problem appear when the Header has no idea which content to continue to next step. If you don't want to refactor than it's ok, there will be a workaround. But my suggestion is that you combine the header and the content into 1 ViewHolder, keep the title, more text, and items inside 1 Model class too. They need to go with each other so they know how to handle with interaction

how to fix wrong alertDialog on a Click?

I have 2 TextViews showing on the main UI. I associate each TextView to a unique clickListener that launches a unique AlertDialog for the user to make a selection. The first TextView is launching the second layout for the second AlertDialog rather than the expected first layout for the first AlertDialog. What am I missing here?
activity_main.xml file
...
<TextView
android:id="#+id/fList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:text="filter"
android:textStyle="bold|italic"
android:textColor="#color/text_primary"
/>
<TextView
android:id="#+id/qList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="quickList"
android:textStyle="bold"
android:textColor="#color/text_primary"
android:gravity="center"
/>
MainActivity.java file
public class MainActivity extends AppCompatActivity
...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView mTextViewFilter = (TextView)findViewById(R.id.fList);
TextView mTextViewQuickList = (TextView)findViewById(R.id.qList);
mTextViewFilter.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view){
final AlertDialog.Builder alertDialogFilter = new AlertDialog.Builder(MainActivity.this);
LayoutInflater inflaterFilter = getLayoutInflater();
final ViewGroup nullParent = null;
// the AlertDialog layout for the first TextView click.
final View dialogLayoutFilter = inflaterFilter.inflate(R.layout.filter_main, nullParent);
alertDialogFilter.setView(dialogLayoutFilter);
final AlertDialog dialogFilter = alertDialogFilter.show();
...
}
});
mTextViewQuickList.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
LayoutInflater inflater = getLayoutInflater();
final ViewGroup nullParent = null;
// the AlertDialog layout for the second TextView click.
final View dialogLayout = inflater.inflate(R.layout.entire_layout, nullParent);
alertDialog.setView(dialogLayout);
final AlertDialog dialog = alertDialog.show();
...
}
});
entire_layout.xml
...
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="380dp"
android:minHeight="160dp" >
<ImageView
android:id="#+id/imageViewX"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:paddingRight="20dp"
android:paddingEnd="20dp"
android:contentDescription="x"
android:src="#drawable/ic_close_white_24dp" />
<TextView
android:id="#+id/FullList"
android:layout_below="#+id/imageViewX"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:textStyle="bold"
android:textAppearance="#android:style/TextAppearance.Large"
android:text="Show entire list" />
<TextView
android:id="#+id/fullNewest"
android:layout_below="#+id/FullList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="40dp"
android:layout_marginLeft="40dp"
android:layout_marginBottom="10dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:text="Created ... />
filter_main.xml
...
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="380dp"
android:minHeight="280dp" >
<ImageView
android:id="#+id/imageViewX"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:paddingRight="20dp"
android:paddingEnd="20dp"
android:contentDescription="x"
android:src="#drawable/ic_close_white_24dp" />
<TextView
android:id="#+id/Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageViewX"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:textStyle="bold"
android:textAppearance="#android:style/TextAppearance.Large"
android:text="Filter..." />
<TextView
android:id="#+id/AllDos"
android:layout_below="#+id/Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="40dp"
android:layout_marginLeft="40dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:text="All..." />
<TextView
android:id="#+id/AllBuys"
android:layout_below="#+id/AllDos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="40dp"
android:layout_marginLeft="40dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:text="All..." />
<TextView
android:id="#+id/AllWork"
android:layout_below="#+id/AllBuys"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="40dp"
android:layout_marginLeft="40dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:text="All..." />
<TextView
android:id="#+id/AllHome"
android:layout_below="#+id/AllWork"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="40dp"
android:layout_marginLeft="40dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:text="All..." />
<TextView
android:id="#+id/AllWaitingfor"
android:layout_below="#+id/AllHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="40dp"
android:layout_marginLeft="40dp"
android:layout_marginBottom="5dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:text="All..." />
Not sure what your textviews' parent is but since you are using attributes like:
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
I guess it is a RelativeLayout.
Since you aren't using neither an orientation nor a relative position, I suppose your TextViews are both on the same line, with just a different margin top, but the quick list TextView has width match_parent and gravity center
android:layout_width="match_parent"
android:gravity="center"
So what's happening is something like this:
And your click always triggers the second TextView that covers entirely the first one.
To fix it change your quick list TextView this way:
<TextView
android:id="#+id/qList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="quickList"
android:textStyle="bold"
android:textColor="#color/text_primary"
android:layout_centerHorizontal="true"/>
With the attributes:
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
It will be centered but not overlapping the first TextView.
I hope this could help, if instead I am wrong and your activity_main.xml file differs, please update your code so that it can be easier figure out any alternative problem.

How to change DialogFragment size

I have a dialogFragment in my Android application with some views as you can see in the image below:
I am trying to change its size without success, in the Java class I am trying to do this:
getDialog().getWindow().setLayout(800,800);
getDialog().setTitle("Please tell us"); as you can see in the code below:
public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log.d(TAG, "onCreateView(LayoutInflaterm ViewGroup, Bundle) - Ini ");
View view = inflater.inflate(R.layout.dialog_box_layout, container, false);
ageSpinner = (Spinner) view.findViewById(R.id.age_spinner_dialog);
ageSpinner.setSelected(false);
ageSpinner.setAdapter(populateAgeSpinner());
ageSpinner.setOnItemSelectedListener(this);
radioDialogMale = (RadioButton) view.findViewById(R.id.radioDialogM);
radioDialogMale.setSelected(false);
radioDialogMale.setOnClickListener(this);
radioDialogFemale = (RadioButton) view.findViewById(R.id.radioDialogF);
radioDialogFemale.setSelected(false);
radioDialogFemale.setOnClickListener(this);
okButton = (Button) view.findViewById(R.id.dialog_ok);
okButton.setOnClickListener(this);
getDialog().getWindow().setLayout(800,800);
getDialog().setTitle("Please tell us");
communicator = (LoginActivity) getActivity();
setCancelable(false);
Log.d(TAG, "onCreateView(LayoutInflaterm ViewGroup, Bundle) - Fi ");
return view;
}
but nothing changes.
here is the layout file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000">
<!-- <TextView
android:id="#+id/dialog_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Please tell us your age and gender"
android:textSize="22dp"
android:layout_marginTop="15dp"
android:layout_centerHorizontal="true"
android:gravity="center"
android:textColor="#FFF"
android:textStyle="bold"
android:layout_marginBottom="30dp"/> -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFF"
android:text="Age"
android:textSize="18dp"
android:gravity="center"/>
<Spinner
android:id="#+id/age_spinner_dialog"
android:layout_width="80dp"
android:spinnerMode="dropdown"
android:layout_height="30dp"
android:layout_marginLeft="18pt"
android:foregroundTint="#color/com_facebook_button_send_background_color"
android:backgroundTint="#FFF"/>
<TextView
android:id="#+id/text_gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50pt"
android:text="Gender"
android:textColor="#FFF"
android:textSize="18dp"
android:layout_alignTop="#+id/radioGroup"
android:layout_toEndOf="#+id/age_spinner" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="0.70"
android:layout_marginEnd="25dp"
android:layout_marginLeft="20dp"
android:id="#+id/radioGroup"
android:layout_alignParentEnd="true">
<RadioButton
android:layout_width="50dp"
android:layout_height="25dp"
android:text="M"
android:layout_marginLeft="12dp"
android:id="#+id/radioDialogM"
android:layout_marginBottom="30dp"
android:textColor="#color/com_facebook_button_send_background_color"
android:backgroundTint="#color/com_facebook_button_send_background_color"
android:buttonTint="#color/com_facebook_button_send_background_color"/>
<RadioButton
android:layout_width="50dp"
android:layout_height="25dp"
android:text="F"
android:id="#+id/radioDialogF"
android:layout_marginRight="5pt"
android:textColor="#color/com_facebook_button_send_background_color"
android:backgroundTint="#color/com_facebook_button_send_background_color"
android:buttonTint="#color/com_facebook_button_send_background_color"/>
</RadioGroup>
/>
<Button
android:layout_width="wrap_content"
android:layout_height="30dp"
android:id="#+id/dialog_ok"
android:background="#color/com_facebook_button_send_background_color"
android:textColor="#FFF"
android:text="OK"
android:layout_below="#+id/radioGroup"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp" />
</RelativeLayout>
help please !!!
You can try to set the width and height for dialog fragment from onResume() method. like below:
public void onResume()
{
super.onResume();
Window window = getDialog().getWindow();
window.setLayout(width, height);
window.setGravity(Gravity.CENTER);
//TODO:
}

Problema with InfoWindowAdapter laytout

I implemented one layout to use on popup of map marker (Maps V2), but I cant configure my layout as I need.
In the image bellow, you can see that the popup with informations about the marker have a white border, I need remove it. I neet fill the popup background with yellow (as the center box).
What is wrong in my layout xml?
My XML (info_window_map)
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/pastel" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#color/blue_nightsky"
android:orientation="horizontal"
>
<TextView
android:id="#+id/linha_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Linha "
android:textColor="#color/white"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:id="#+id/cod_linha"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:textColor="#color/white"
android:textSize="13sp"
android:layout_gravity="left"
android:layout_marginLeft="5dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/onibus_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ônibus....: "
android:textColor="#color/black"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="#+id/cod_onibus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/previsao_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Previsão..: "
android:textColor="#color/black"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="#+id/previsao"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
My Adapter (that use the xml)
class MyInfoWindowAdapter implements InfoWindowAdapter{
private final View myContentsView;
MyInfoWindowAdapter(){
myContentsView = getLayoutInflater().inflate(R.layout.info_window_map, null);
}
#Override
public View getInfoContents(Marker marker) {
//Seta a linha no infowindow
TextView txtTitle = ((TextView)myContentsView.findViewById(R.id.cod_linha));
txtTitle.setText(marker.getTitle());
//Pega a informação em snippet e separa linha, codOnibus do endereço
String snippet = marker.getSnippet();
Snippet snp = new Snippet();
snp.fillSnippet(snippet);
TextView txtCodLinha = ((TextView)myContentsView.findViewById(R.id.cod_linha));
txtCodLinha.setText(snp.getLinha());
TextView txtCodOnibus = ((TextView)myContentsView.findViewById(R.id.cod_onibus));
txtCodOnibus.setText(snp.getCodOnibus());
TextView txtPrevisao = ((TextView)myContentsView.findViewById(R.id.previsao));
txtPrevisao.setText(snp.getPrevisao());
return myContentsView;
}
#Override
public View getInfoWindow(Marker marker) {
// TODO Auto-generated method stub
return null;
}
}

Multiple textviews are not shown in Linear layout

i try to develop a small Android app and i use fragments for tab feature. Here is my tab3's layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF0000"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/European_Central_Bank" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Türk Lirası: " />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dolar:" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Japon Yeni:" />
</LinearLayout>
And this is the Java part:
public class Tab3Fragment extends Fragment {
private String turkishLira;
private String dollar;
private String japaneseMoney;
URL url;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View myCreateView=(LinearLayout)inflater.inflate(R.layout.tab_frag3_layout, container, false);
getCurrencyInfo();
TextView textView1 = (TextView) myCreateView.findViewById(R.id.textView1);
TextView textView2 = (TextView) myCreateView.findViewById(R.id.textView2);
TextView textView3 = (TextView) myCreateView.findViewById(R.id.textView3);
textView1.setText(turkishLira);
textView2.setText(dollar);
textView3.setText(japaneseMoney);
return myCreateView;
}
getCurrencyInfo() {...}
}
The question is only the first textview is shown on the phone. If i swap the 1st and 2nd textview, this time 2nd textview which has a static content is shown.
What am i missing? I don't have any problem in getCurrencyInfo method, i printed it's results.
Thanks, in advance.
My guess is that turkishLira, dollar, or japaneseMoney might be null or empty.
Have you debugged getCurrencyInfo() method?
You should maybe try
textView1.setText("turkishLira");
textView2.setText("dollar");
textView3.setText("japaneseMoney");
This will let you check wether this is a layout issue or a getCurrencyInfo() issue.
Make your XML file like this:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/European_Central_Bank" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Türk Lirası: " />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Dolar:" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Japon Yeni:" />

Categories

Resources