Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

Want Count ListView Items and show counter on every ListView Items

Course Queries Syllabus Queries
Max. 2000 characters
Replies

usr_profile.png
Yasmin Mirza

User

( 6 months ago )

I got stuck in Counting ListView items and show Counters on Particular ListView Items . Pleas see below for actually what I want to do:

Here's a sample of ListView Items:

Syllabus (List Items Counting) < My Heading >

Ex.

  • Syllabus (1/10) Android
  • Syllabus (2/10) Java
  • Syllabus (10/10) Java
  • ...more

I am getting these list view items from My Local Database, Please suggest me any ideas

usr_profile.png
Peter Jarvis

User

( 6 months ago )

I recommend to you create subclass of some ListAdapter and in getView() method just use int position for getting position of each child and size of datasource for getting total count.

For example if you'll use SimpleCursorAdapter so use cursor.getCount() for count of items and int position parameter of getView() method for getting position of each child(row).

Basic example:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
   if (c.moveToPosition(position) { 
      String name = c.getString(c.getColumnIndex(Constants.COL));
      String another = c.getString(c.getColumnIndex(Constants.COL_2));
      String text = value + "(" + String.valueOf(position) + "/" + String.valueOf(c.getCount()) + ") " + another; 
      textView.setText(text);
   }
}

what's your interest


forum_ban8_5d8c5fd7cf6f7.gif