简体   繁体   中英

TextView, won't set text

I have a hashmap full of values which will populate the listview. the image sets fine but the text does not. The hashmap is not null, just some odd reason why it would not display. Any help would be appreciated

public View getView(int position, View convertView, ViewGroup parent) {
    View vi=convertView;
    if(convertView==null){
        vi = inflater.inflate(R.layout.list_row, null);
    }
    TextView description = (TextView)vi.findViewById(R.id.description); 
    TextView username = (TextView)vi.findViewById(R.id.usernamae); 
    TextView likes = (TextView)vi.findViewById(R.id.likes); 
    ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image
    HashMap<String, String> song = new HashMap<String, String>();        
    song = data.get(position);
    description.setText(song.get(MenuActivity.KEY_description));
    username.setText(song.get(MenuActivity.KEY_username));
    likes.setText(song.get(MenuActivity.KEY_likes));
    imageLoader.DisplayImage(song.get(MenuActivity.KEY_THUMB_URL), thumb_image);
    return vi;
}
 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/list_selector"
    android:orientation="horizontal"
    android:padding="5dip" >

   <LinearLayout android:id="@+id/thumbnail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="3dip"
        android:layout_alignParentLeft="true"
        android:background="@drawable/image_bg"
        android:layout_marginRight="5dip">

        <ImageView
            android:id="@+id/list_image"
            android:layout_width="50dip"
            android:layout_height="50dip"
           />

    </LinearLayout>

    <TextView
        android:id="@+id/description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/thumbnail"
        android:layout_toRightOf="@+id/thumbnail"
        android:textColor="#040404"
        android:typeface="sans"
        android:textSize="15dip"
        android:textStyle="bold"/>

    <TextView
        android:id="@+id/username"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/description"
        android:textColor="#343434"
        android:textSize="10dip"
        android:layout_marginTop="1dip"
        android:layout_toRightOf="@+id/thumbnail" />

     <TextView
        android:id="@+id/likes"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@id/username"
        android:gravity="right"
        android:layout_marginRight="5dip"
        android:textSize="10dip"
        android:textColor="#10bcc9"
        android:textStyle="bold"/>


     <ImageView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"/>

</RelativeLayout>

Try use description.setText(String.valueOf(song.get(MenuActivity.KEY_description)));

Also try rebuild your project.

EDIT:

I watch your xml, you also add extra ", look:

android:id="@+id/"description"

need write like this:

 android:id="@+id/description"

I was able to show text using the layout you provided above, but only for "description" and "username", "likes" is hidden behind the last ImageView, try using android:layout_toLeftOf="@id/id_of_image" for likes. I only did a quick test with square images, depending on your actual images, you might have more hidden views, but this confirms the issue lies with the xml. Try rearranging your xml so your views don't overlap each other. Happy coding !

Have you tried if text shows in the TextViews, if you hard-code a string in the layout XML for the TextViews? Maybe the views are just not visible, try re-arranging your layout in that case.

     description.setText(song.get(MenuActivity.KEY_description).toString());
     username.setText(song.get(MenuActivity.KEY_username).toString());
     likes.setText(song.get(MenuActivity.KEY_likes).toString());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM