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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:07:06+00:00 2026-05-30T03:07:06+00:00

I am making an android application that uses a listview. I want to get

  • 0

I am making an android application that uses a listview. I want to get the index number of an item once an item has been pressed(single-click). I’ve gone through several tutorials, but none seemed to help. How can i get the index number and pass it to a String. I do then want to delete it, but i’ll manage that part my self. I only need the index number and pass it to a string. The code where i’ll get the index number is straigt after the onCreate method. Please help and thanks in advance! This is the code that i am using:

public class NotesActivity extends ListActivity implements OnClickListener {
/** Called when the activity is first created. */
List<String> myList = new ArrayList<String>();
EditText AddItemToListViewEditText;
Button AddItemToListView, AddItemToListViewButton, CancelButton, DeleteButton;
LinearLayout AddItemToListViewLinearLayout, DeleteItemFromListViewLinearLayout;
public String DeleteIndexNumber;
  static final String[] COUNTRIES = new String[] {
      "Matte på A1 med Ole", "Engelsk på klasserommet", "Film på A1 etter friminuttet"
      };
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.notes);
    setListAdapter((ListAdapter) new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES));
    setListAdapter((ListAdapter) new ArrayAdapter<String>(this, R.layout.list_item, myList));

    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(), "Note: " + ((TextView) view).getText(),
            Toast.LENGTH_SHORT).show();
        //This is where i need the index number to be passed to the string "DeleteIndexNumber"
        DeleteItemFromListViewLinearLayout = (LinearLayout)findViewById(R.id.DeleteItemFromListViewLinearLayout);
        DeleteItemFromListViewLinearLayout.setVisibility(View.VISIBLE);
  }
    });
  }
@Override
public boolean onCreateOptionsMenu(Menu meny) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.listviewmenubuttons, meny);
    return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
    case R.id.AddItemToListView:
        AddItemToListViewButton = (Button)findViewById(R.id.AddItemToListViewButton);
        CancelButton = (Button)findViewById(R.id.CancelButton);
        DeleteButton = (Button)findViewById(R.id.DeleteButton);
        CancelButton.setOnClickListener(this);
        DeleteButton.setOnClickListener(this);
        AddItemToListViewLinearLayout = (LinearLayout)findViewById(R.id.AddItemToListViewLinearLayout);
        AddItemToListViewButton.setOnClickListener(this);
        AddItemToListViewLinearLayout.setVisibility(View.VISIBLE);
        break;
        }
    return true;
}
public void onClick(View src) {
    switch(src.getId()) {
    case R.id.AddItemToListViewButton:
        AddItemToListViewEditText = (EditText)findViewById(R.id.AddItemToListViewEditText);
        myList.add(AddItemToListViewEditText.getText().toString());
        ((ArrayAdapter)getListView().getAdapter()).notifyDataSetChanged(); 
        AddItemToListViewEditText.setText("");
        AddItemToListViewEditText.clearFocus();
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput (InputMethodManager.SHOW_FORCED, InputMethodManager.RESULT_HIDDEN);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
        AddItemToListViewLinearLayout.setVisibility(View.GONE);
        break;
    case R.id.CancelButton:
        DeleteItemFromListViewLinearLayout = (LinearLayout)findViewById(R.id.DeleteItemFromListViewLinearLayout);
        DeleteItemFromListViewLinearLayout.setVisibility(View.INVISIBLE);
        break;
    case R.id.DeleteButton:
        break;
    }
}
}
  • 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-05-30T03:07:07+00:00Added an answer on May 30, 2026 at 3:07 am

    notice the parameters for the onItemClick method

    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    }
    

    position will give you the index you desire..

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

Sidebar

Related Questions

I'm making an Android application that reads an XML Internet. This application uses SAX
I am making an android application that will play an mp3 file once a
i am making one application in Android 2.2 in that application i want to
I am making an android application that uses these views: (Root) - LinearLayout (Child
I am making an android application that needs to use a ListView . I
I am making an HTTP get request to a website for an android application
I have learned that when using android:entries with a ListView , it uses android.R.layout.simple_list_item_1
I'm in the process of making an Android application that creates a new file
I'm making an application for Android that needs to react to when the device
I am making a email sending application in android phone. For that I included

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.