rmaik
rmaik

Reputation: 1086

how to make all the textView in a listview of a navigationdrawer marquee simultaneously?

in my App i have a Navigation Drawer, the ListView of the NavigatinDrawer' has anImageView,TextViewand anotherTextViewwith idtv_navDrawerOptionDescription`as shown below.

the number of items in the ListView of the navigation drawer are three items (eco-assist, data-logger-exit) each of them has ImageView, TextView"as title" and another TextView" as description"

what i want to do is, when the drawer is opened, all the "description TextView" of three items i have in the NavigationDrawer ListView should be rotation horizontally forever as marquee.

when i run the App. i found the description textview is static and not rotating

my attempts are posted belwo the layout of the listview of the navigationDrawer

<?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"
android:background="@drawable/list_selector">

<ImageView 
    android:id="@+id/iv_navDrawerOptionImage"
    android:layout_width="25dp"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_marginLeft="12dp"
    android:layout_marginRight="12dp"
    android:contentDescription="@string/desc_list_item_icon"
    android:layout_centerVertical="true"/>

<TextView 
    android:id="@+id/tv_navDrawerOptionTitle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:layout_toEndOf="@id/iv_navDrawerOptionImage"
    android:minHeight="?android:attr/listPreferredItemHeightSmall"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:textColor="@color/list_item_title"
    android:gravity="center_vertical"/>

  <TextView 
    android:id="@+id/tv_navDrawerOptionDescription"
    android:layout_below="@id/tv_navDrawerOptionTitle"
    android:singleLine="true"
    android:lines="1"
    android:ellipsize="marquee"
    android:fadingEdge="horizontal"
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

NavigationDrawer ListAdapter:

public class NavDrawerListAdapter extends BaseAdapter{

private Context context;
private ArrayList<NavDrawerModell> navDrawerModel;

public NavDrawerListAdapter(Context context, ArrayList<NavDrawerModell> navDrawerModell) {
    // TODO Auto-generated constructor stub
    this.context = context;
    this.navDrawerModel = navDrawerModell;
}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return this.navDrawerModel.size();
}

@Override
public Object getItem(int position) {
    // TODO Auto-generated method stub
    return this.navDrawerModel.get(position);
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    if (convertView == null) {
        LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        convertView = layoutInflater.inflate(R.layout.drawer_list_layout, null);
    }

    ImageView iv_Icon = (ImageView) convertView.findViewById(R.id.iv_navDrawerOptionImage);
    TextView tv_Title = (TextView) convertView.findViewById(R.id.tv_navDrawerOptionTitle);
    TextView tv_Desc = (TextView) convertView.findViewById(R.id.tv_navDrawerOptionDescription);

    iv_Icon.setImageResource(navDrawerModel.get(position).getIcon());
    tv_Title.setText(navDrawerModel.get(position).gettitle());
    tv_Desc.setText(navDrawerModel.get(position).getDescription());

    return convertView;
  }
  }

Upvotes: 0

Views: 848

Answers (1)

Varun Singh
Varun Singh

Reputation: 1145

<TextView
android:id="@+id/tv_navDrawerOptionDescription"
android:layout_below="@id/tv_navDrawerOptionTitle" 
android:layout_width="fill_parent"
android:layout_height="wrap_content" 
android:singleLine="true"
android:ellipsize="marquee" 
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true">

Please try the above code and see if this works.

EDIT:

In getView function of the subclasses BaseAdapter add the following code:

tv_Desc.setText(navDrawerModel.get(position).getDescription());
tv_Desc.setSelected(true);
tv_Desc.requestFocus();

Upvotes: 2

Related Questions