0% found this document useful (0 votes)
63 views4 pages

Android ListView Click to Details

This document contains code for an Android app that displays a list of items in a ListView. When an item is clicked, it opens a new activity with details about that item. The main activity defines a list of sample items, sets up the ListView adapter, and starts the details activity when an item is clicked. The details activity gets the selected item from the intent, displays it, and sets click listeners on buttons to handle bidding and adding to a cart.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views4 pages

Android ListView Click to Details

This document contains code for an Android app that displays a list of items in a ListView. When an item is clicked, it opens a new activity with details about that item. The main activity defines a list of sample items, sets up the ListView adapter, and starts the details activity when an item is clicked. The details activity gets the selected item from the intent, displays it, and sets click listeners on buttons to handle bidding and adding to a cart.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import [Link].

Intent;

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

public class MainActivity extends AppCompatActivity {

private ListView listView;

private List<String> itemList;

@Override

protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_main);

// Initialize the item list

itemList = new ArrayList<>();

[Link]("Item 1");

[Link]("Item 2");

[Link]("Item 3");

// Set up the ListView


listView = findViewById([Link]);

ArrayAdapter<String> adapter = new ArrayAdapter<>(this, [Link].simple_list_item_1,


itemList);

[Link](adapter);

// Handle item click events

[Link](new [Link]() {

@Override

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

String selectedItem = [Link](position);

Intent intent = new Intent([Link], [Link]);

[Link]("selectedItem", selectedItem);

startActivity(intent);

});

```

*[Link]*

```java

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];
public class ItemDetailsActivity extends AppCompatActivity {

private TextView itemNameTextView;

private Button bidButton, addToCartButton;

private String selectedItem;

@Override

protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_item_details);

// Get the selected item from the intent

selectedItem = getIntent().getStringExtra("selectedItem");

// Set up the UI elements

itemNameTextView = findViewById([Link]);

bidButton = findViewById([Link]);

addToCartButton = findViewById([Link]);

[Link](selectedItem);

// Handle bid button click

[Link](new [Link]() {

@Override

public void onClick(View v) {

// Implement bidding logic here

});
// Handle add to cart button click

[Link](new [Link]() {

@Override

public void onClick(View v) {

// Implement add to cart logic here

});

You might also like