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

  • SEARCH
  • Home
  • 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 8645005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:26:14+00:00 2026-06-12T12:26:14+00:00

I want to use custom List adapter in this example so that I can

  • 0

I want to use custom List adapter in this example so that I can get the benefit of getView()
and then get the id for the buttons in list view.

So that I will be able to retrieve (name_id) student from database as list with delete buttons.

And I want to implement delete so that when a user clicks delete it will take the id of student and delete it from database.

How can I change my adapter here to a custom List adapter?

My code is the following:

public class ManageSection extends ListActivity {

//ProgresogressDialog pDialog;

    private ProgressDialog pDialog;

    // Creating JSON Parser object

// Creating JSON Parser object
JSONParser jParser = new JSONParser(); //class
boolean x =true; 

ArrayList<HashMap<String, String>> studentList;

//url to get all products list
private static String url_all_student = "http://10.0.2.2/SmsPhp/view_student_info.php";
// JSON Node names
private static final String TAG_SUCCESS = "success";
private static final String TAG_student = "student";
private static final String TAG_StudentID = "StudentID";
private static final String TAG_StudentNo = "StudentNo";
private static final String TAG_FullName = "FullName";
// course JSONArray
JSONArray student = null;
private TextView mDateDisplay;
private int mYear;
private int mMonth;
private int mDay;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.manage_section);
        mDateDisplay = (TextView) findViewById(R.id.day);

        // add a click listener to the button

        // get the current date

        final Calendar c = Calendar.getInstance();
       mYear = c.get(Calendar.YEAR);
      mMonth = c.get(Calendar.MONTH);
        mDay = c.get(Calendar.DAY_OF_MONTH);
        mDateDisplay.setText(mDay+"-"+mMonth+"-"+mYear);


        studentList = new ArrayList<HashMap<String, String>>();



     // on seleting single course
        // launching Edit course Screen
         // on seleting single course
           // launching Edit course Screen




        new LoadAllstudent().execute();


    }


    /**
     * Background Async Task to Load all student by making HTTP Request
     * */
    class LoadAllstudent extends AsyncTask<String, String, String>
    {

        /**
         * Before starting background thread Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(ManageSection.this);
            pDialog.setMessage("Loading student. Please wait...");
            pDialog.setIndeterminate(false);
                  }




        /**
         * getting All student from u r l
         * */
        @Override
        protected String doInBackground(String... args) {
            // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            // getting JSON string from URL
            JSONObject json = jParser.makeHttpRequest(url_all_student, "GET", params);

            // Check your log cat for JSON response
            Log.d("All student : ", json.toString());

            try {
                // Checking for SUCCESS TAG
                int success = json.getInt(TAG_SUCCESS);

                if (success == 1)
                {
                    // student found
                    // Getting Array of course
                    student = json.getJSONArray(TAG_student);

                    // looping through All courses
                    for (int i = 0; i < student.length(); i++)//course JSONArray
                    {
                        JSONObject c = student.getJSONObject(i); // read first

                        // Storing each json item in variable
                        String StudentID = c.getString(TAG_StudentID);
                        String StudentNo = c.getString(TAG_StudentNo);
                        String FullName = c.getString(TAG_FullName);

                        // creating new HashMap
                        HashMap<String, String> map = new HashMap<String, String>();

                        // adding each child node to HashMap key => value
                        map.put(TAG_StudentID, StudentID);
                        map.put(TAG_StudentNo, StudentNo);
                        map.put(TAG_FullName, FullName);

                        // adding HashList to ArrayList
                        studentList.add(map);
                    }
                } else {
                    x=false;

                }

            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }   

        /**
         * After completing background task Dismiss the progress dialog
         * **/
        protected void onPostExecute(String file_url) { 
              // dismiss the dialog after getting all products 
              pDialog.dismiss(); 
              if (x==false)
                Toast.makeText(getBaseContext(),"no student" ,Toast.LENGTH_LONG).show();

              ListAdapter adapter = new SimpleAdapter( 
                      ManageSection.this,  studentList, 
                        R.layout.list_student, new String[] { TAG_StudentID, 
                              TAG_StudentNo,TAG_FullName}, 
                        new int[] { R.id.StudentID, R.id.StudentNo,R.id.FullName}); 
               setListAdapter(adapter); 

             // Updating parsed JSON data into ListView 

        } 


    }
}

Note that if there is an easy way without changing the adapter I could make an id for each button.
Because I heard that I must use custom list adapter…

  • 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-12T12:26:15+00:00Added an answer on June 12, 2026 at 12:26 pm

    Use setListAdapter here to use a custom adapter for your ListActivity: http://developer.android.com/reference/android/app/ListActivity.html#setListAdapter(android.widget.ListAdapter)

    You will then be able to tag your views with their Ids etc.

    Another way to do it without a custom adapter (simpler but not preferred) is to map all the entries manually with the position on the list. (since you can supply an array of elements, you can just use the position to get the object). That being said, if you simply want to hook up the buttons, you can let onClick to record the position of the element and then when they press the button you can react correctly by accessing the array.

    EDIT:

    In your onCreate do:

    getListView().setOnItemClickListener(new OnItemClickListener() {

    public void onItemClick(AdapterView<?> parent, View view, final int pos, long id){
        selected_student=studentList.get(pos); //member of your activity.
    });
    

    And then in your button onClickListener you just do delete(selected_student);

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

Sidebar

Related Questions

I want to use custom exception handling, for example instead of using (Exception ex)
For example I want to use custom logger: logger = require('basic-logger'), logger.setLevel('info') var customConfig
I want to use a custom class that could handle querying easily. Are there
Just want to ask if i can use Custom Validator in client side without
I am trying to do a custom bullet list. However, I want to use
I want to use SOSL to get relationship values? List<List<SObject>> searchList = [FIND :mySearchText
Here is a short List activity that calls a custom adapter to show class
I want to make a custom List View having Two TextViews and a radio
I want to use Custom URL Scheme to transfer data from application to other
I want to use a custom template file which shoud use the base layout

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.