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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:46:11+00:00 2026-06-05T16:46:11+00:00

I have dynamic listview on my android client app that receive data from remote

  • 0

I have dynamic listview on my android client app that receive data from remote mysql DB. I have a context menu that opens on user click on any row i that listview. There is an option named’ add to cart’ on that menu. I want to add the clicked row item to the cart when that context menu option is selected. So how do I get the row ID for adding that slected/clicked row item to the cart just like shopping carts? I later need to display the selected row item in my ‘Show Cart’ class..Pls help..thanks in advance. I didnt find much articles that discuss about it with actual code .my listview display class is here:

public class MainMenu extends ListActivity {
Intent intent = getIntent();
InputStream is;
@Override

public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  String result = "";
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://10.0.2.2/phpmyadmin/php.php");
           HttpResponse response = null;
    try {
        response = httpclient.execute(httppost);
    } catch (ClientProtocolException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } 
    HttpEntity entity = response.getEntity();
    try {
        is = entity.getContent();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {

        e.printStackTrace();
    }
    Log.e("log_tag", "connection success ");

    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    StringBuilder sb = new StringBuilder();
    String line = null;
    try {
        while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");

        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        is.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    result=sb.toString();


    JSONArray jArray = null;
    try {
        jArray = new JSONArray(result);
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    int arrayLength=jArray.length();
    String F_NAME[]=new String[arrayLength];

    for(int i=0;i<arrayLength;i++){
           JSONObject json_data = null;
        try {
            json_data = jArray.getJSONObject(i);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
           try {
            F_NAME[i]=json_data.getString("F_NAME");
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }}
setListAdapter(new ArrayAdapter<String>(this, R.layout.list,F_NAME));
ListView lv = getListView();
    lv.setTextFilterEnabled(true); registerForContextMenu(lv);}

 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.fltmenu, menu); menu.setHeaderTitle("Ask for");}
public boolean onContextItemSelected(MenuItem item) { //find out which menu item was pressed switch (item.getItemId()) {
        case R.id.ToCart:
            Dotocart();
            return true;
            default:
            return false;}}private void Dotocart() {}
  • 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-05T16:46:13+00:00Added an answer on June 5, 2026 at 4:46 pm
        @Override
        public boolean onContextItemSelected(MenuItem item) {
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
                int menuItemIndex = item.getItemId();
                int position = (info.position);
    ....
    

    the menuItem index returns the context menu item selected (add to chart, …) and the info.position the position of the list that was clicked. (if you also have the list of data that populated the list view you can get it by the same index.

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

Sidebar

Related Questions

I have a doubt in listview android. I am getting 3 dynamic values from
I have a listview that loads dynamic controls from xml/xslt <asp:ListView ID=DynamicFields runat=server DataSourceID=CustomFields
I have a ListView that is filled with a dynamic set of data each
I have learned that when using android:entries with a ListView , it uses android.R.layout.simple_list_item_1
I have a ListView in a WPF Application that use Dynamic Binding . I
i have a Listview with dynamics rows that read them from database. now i
I have dynamic array filled with bytes, which are read from .raw file with
I have some divs that have dynamic heights controlled by a 'click' function as
I have some divs that have dynamic heights controlled by a 'click' function as
I have a dynamic value that is being stored in a PHP variable. The

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.