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 7815199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:26:49+00:00 2026-06-02T05:26:49+00:00

I am new to android. I am developing an application in which there is

  • 0

I am new to android. I am developing an application in which there is a list view of students with edit and delete buttons. Like


 STUDENT LIST

[ABC]              [edit]              [delete]

[DEF]              [edit]              [delete]


With this code im able to list student details in a <Textview>

public class DataBaseDemoActivity extends ListActivity {
/** Called when the activity is first created. */
  SQLiteDatabase db;
  Button btnInsert;
  ArrayAdapter<String> students;

  @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  try{
  db=openOrCreateDatabase("StudentDB",SQLiteDatabase.CREATE_IF_NECESSARY,null);

  Cursor c=db.rawQuery("SELECT * FROM temp",null);
  String[] students = new String[c.getCount()];

  if (c.moveToFirst())
  {                       
      for (int i = 0; i < c.getCount(); i++)
      {
          students[i] = c.getString(0).toString()+" "+c.getString(1).toString();
          c.moveToNext();
      }           
  }
  c.close();

  setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, students));

  ListView lv = getListView();
  lv.setTextFilterEnabled(true);

  lv.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view,
        int position, long id) {
      // When clicked, show a toast with the TextView text
      Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
          Toast.LENGTH_SHORT).show();
    }
  });


  }catch(SQLException e)
  {
  }
}

}

I need to store the id of the record with in the list view so that when i click on the edit or delete button, i’ll have to find out the id and make changes on the DB. How can i set values to two fields say <TextView>[show details] and <EditText>[visibility: insisible – to save id of the record]. I am able to get the details to the <TextView> using the above code. Any suggestion will be appreciated.

UPDATE :

Layout i am using

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"    
    >
    <EditText 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="invisible"
        android:inputType="text"
        android:onClick="showInfo"
        />
    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="230dip"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:id="@+id/studentInfo" >
    </TextView>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/action"
        android:onClick="showInfo"
         />

</LinearLayout>
  • 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-02T05:26:51+00:00Added an answer on June 2, 2026 at 5:26 am

    You can get the Id within cursor data fetch loop, use any HashMap<id,String> collection for it and store id along with data (text).

    As per your requirement, I suggest you to use SimpleCursorAdapter instead of ArrayAdapter with ListView.

    So you can manage easily your database records with your list and also get the all information related to database for particular record when List Item clicked.

    Look at SimpleCursorAdapters and ListViews

    Creating a custom CursorAdapter for Android

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

Sidebar

Related Questions

I am developing Android Application. In which i am having list view with text
I am developing one android application which select wifi access point from list of
i am new bie in android, I am developing an application in Android, and
I am very new to android and I am developing this app which allows
Hi there Im new to mobile application development. I had developed Android apps using
I am developing an android application in which i have created five tabs and
I am developing a Android application which communicates with a PHP server via JSON.
I am developing an android application in which i need to give some features
I'm currently developing a camera application for Android on which some problems have occurred.
I am developing an android application , in which i am using a gif

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.