Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8139587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:52:29+00:00 2026-06-06T11:52:29+00:00

I need some help with my project. I’ve created a Custom Adapter, since I

  • 0

I need some help with my project. I’ve created a Custom Adapter, since I want my List View to display 5 textview, instead of one that I managed to do so far. This is my CustomAdapterPn activity:

public class CustomAdapterPn extends BaseAdapter {
private static ArrayList<Poniedzialek> searchPnArrayList;

 private LayoutInflater mInflater;

 public CustomAdapterPn(final Context context, final ArrayList<Poniedzialek> results) {
  searchPnArrayList = results;
  mInflater = LayoutInflater.from(context);
 }

 public int getCount() {
  return searchPnArrayList.size();
 }

 public Object getItem(int position) {
  return searchPnArrayList.get(position);
 }

 public long getItemId(int position) {
  return position;
 }
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
  ViewHolder holder;
  if (convertView == null) {
   convertView = mInflater.inflate(R.layout.entry, null);
   holder = new ViewHolder();
   holder.txtSession = (TextView) convertView.findViewById(R.id.textSession);
   holder.txtName = (TextView) convertView.findViewById(R.id.textName);
   holder.txtStart = (TextView) convertView.findViewById(R.id.textStartTime);
   holder.txtEnd = (TextView) convertView.findViewById(R.id.textEndTime);
   holder.txtRoom = (TextView) convertView.findViewById(R.id.textRoom);

   convertView.setTag(holder);
  } else {
   holder = (ViewHolder) convertView.getTag();
  }

  holder.txtSession.setText(searchPnArrayList.get(position).getTypeOfSession());
  holder.txtName.setText(searchPnArrayList.get(position).getName());
  holder.txtStart.setText(searchPnArrayList.get(position).getStartTime());
  holder.txtEnd.setText(searchPnArrayList.get(position).getEndTime());
  holder.txtRoom.setText(searchPnArrayList.get(position).getRoom());

  return convertView;
 }

 static class ViewHolder {

  TextView txtSession;
  TextView txtName;
  TextView txtStart;
  TextView txtEnd;
  TextView txtRoom;
 }

}

And this is Activity where I wish to use this CustomAdapter. Note that I was using ArrayAdapter to display list items – I didn’t modify the code yet, since I am clueless what should I do to manage this custom adapter correctly ( I was trying to, but nothing worked out well ). I am a newbie, so it’s quite hard for me to get this, although I was reading tons of tutorials.

    public class PoniedzialekActivity extends Activity implements OnClickListener, OnItemClickListener{ // z ListActivity na Activity

    private Button butPnAdd;
    private Button butPnDelete;
    private ListView list_Pn;

    private static final int DIALOG_ALERT = 10;

        // We need some kind of Adapter to made the connection between ListView UI component and SQLite data set.
        private ListAdapter pn_list_adapter;
        // We need this while we read the query using Cursor and pass data
        private ArrayList<Poniedzialek> pn_list;    

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_poniedzialek);

        butPnAdd = (Button) findViewById(R.id.butPnAdd);
        butPnAdd.setOnClickListener(this);

        butPnDelete = (Button) findViewById(R.id.butPnDel);
        butPnDelete.setOnClickListener(this);

        // Initialize UI components
        list_Pn = (ListView) findViewById(R.id.listPn);
        list_Pn.setOnItemClickListener(this);

        pn_list = new ArrayList<Poniedzialek>();

        // For the third argument, we need a List that contains Strings.
        //We decided to display undergraduates names on the ListView.
        //Therefore we need to create List that contains undergraduates names
        pn_list_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, populateList());
        list_Pn.setAdapter(pn_list_adapter);


    }
    @Override
    public void onClick(View v) {
        if(v.getId()==R.id.butPnAdd){
        Intent i = new Intent(PoniedzialekActivity.this,dodawaniePoniedzialek.class);
        startActivity(i);
        }
        if(v.getId()==R.id.butPnDel){
            showDialog(DIALOG_ALERT);
        }
    }
                /**
                 * DIALOG
                 */
                protected Dialog onCreateDialog(int id) {
                    switch (id) {
                    case DIALOG_ALERT:
                        // Create out AlterDialog
                        Builder builder = new AlertDialog.Builder(this);
                        builder.setTitle("Czy na pewno chcesz usunac wszystkie wpisy ?");
                        builder.setCancelable(true);
                        builder.setPositiveButton("Tak", new OkOnClickListener());
                        builder.setNegativeButton("Nie", new CancelOnClickListener());
                        AlertDialog dialog = builder.create();
                        dialog.show();
                    }
                    return super.onCreateDialog(id);
                }
                private final class CancelOnClickListener implements
                DialogInterface.OnClickListener {
                    public void onClick(DialogInterface dialog, int which) {
                        // Nic nie robi
                    }
                }
                private final class OkOnClickListener implements
                DialogInterface.OnClickListener {
                    public void onClick(DialogInterface dialog, int which) {            
                        DeletePn();
                        onResume();
                    }
                }
                public void DeletePn(){ 
                    DatabaseHelper openHelperClass = new DatabaseHelper(this);
                    SQLiteDatabase sqliteDatabase = openHelperClass.getWritableDatabase();

                    sqliteDatabase.delete(DatabaseHelper.PN_TABLE, null, null);

                }
    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        // TODO Auto-generated method stub

    }
        // To create a List that contains undergraduate names, we have to read the SQLite database
        //We are going to do it in the separate method
        public List<String> populateList(){

            // We have to return a List which contains only String values. Lets create a List first
            List<String> pn_string_list = new ArrayList<String>();

            // First we need to make contact with the database we have created using the DbHelper class
            DatabaseHelper openHelperClass = new DatabaseHelper(this);

            // Then we need to get a readable database
            SQLiteDatabase sqliteDatabase = openHelperClass.getReadableDatabase();

            // We need a a guy to read the database query. Cursor interface will do it for us
            //(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy)
            Cursor cursor = sqliteDatabase.query(DatabaseHelper.PN_TABLE, null, null, null, null, null, null);
            // Above given query, read all the columns and fields of the table

            startManagingCursor(cursor);

            // Cursor object read all the fields. So we make sure to check it will not miss any by looping through a while loop
            while (cursor.moveToNext()) {
                // In one loop, cursor read one undergraduate all details
                // Assume, we also need to see all the details of each and every undergraduate
                // What we have to do is in each loop, read all the values, pass them to the POJO class
                //and create a ArrayList of undergraduates

                String session = cursor.getString(cursor.getColumnIndex(DatabaseHelper.PN_KEY_TYPE_OF_SESSION));
                String start = cursor.getString(cursor.getColumnIndex(DatabaseHelper.PN_KEY_START_TIME));
                String end = cursor.getString(cursor.getColumnIndex(DatabaseHelper.PN_KEY_END_TIME));
                String name = cursor.getString(cursor.getColumnIndex(DatabaseHelper.PN_KEY_NAME));
                String room = cursor.getString(cursor.getColumnIndex(DatabaseHelper.PN_KEY_ROOM));

                // Finish reading one raw, now we have to pass them to the POJO
                Poniedzialek pn = new Poniedzialek();
                pn.setTypeOfSession(session);
                pn.setName(name);
                pn.setStartTime(start);
                pn.setEndTime(end);
                pn.setRoom(room);

                // Przekazujemy pn do arraylist
                pn_list.add(pn);
                // But we need a List of String to display in the ListView also.
                // That is why we create "pn_string_list"
                pn_string_list.add(name);
            }
            // Jezeli Baza Danych nie zostanie zamknieta dostaniemy error
            sqliteDatabase.close();
            return pn_string_list;
        }
        // If you don't write the following code, you wont be able to see what you have just insert to the database
        @SuppressWarnings("unchecked")
        @Override
        protected void onResume() {
            super.onResume();
            pn_list_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, populateList());
            list_Pn.setAdapter(pn_list_adapter);
            ((ArrayAdapter<String>) pn_list_adapter).notifyDataSetChanged(); // dodano
            list_Pn.refreshDrawableState(); // dodanoe
            list_Pn.invalidate(); // dodanoe
        }
} // end PoniedzialekActivity
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T11:52:32+00:00Added an answer on June 6, 2026 at 11:52 am

    Look at this lines and make changes according to it,

    CustomAdapterPn pn_list_adapter; //change 1
    
    pn_list = new ArrayList<Poniedzialek>();
    populateList() // Change 2
    pn_list_adapter = new CustomAdapterPn(this,pn_list); // Change 3
    list_Pn.setAdapter(pn_list_adapter);
    

    Try this and let me know what happen..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help with a work project I have been assigned. At the
I'm experiencing some difficulties configuring our project with Maven and need some help :)
Need some help assigning a mouseover event to display some icons that start out
i need some help with c# and nhibernate. I'm working on a project that
I am building a project management app and need some help with how to
I am developing a unit converter for my semester project. I need some help
I need some help regarding Visual Studio solution and project organization. I have a
I desperately need some help.I am doing a StockManagement project.I am not able to
I need some help - I am trying to use a custom validation attribute
I am currently working on a Spring project and I need some help. In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.