• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Clickable ListView / ArrayAdapter items / redirect to activity

How to start new Activies for ArrayAdapter items, passing item values to Activity (TextView widget)

  • Android Activities

    Votes: 0 0.0%
  • Android ArrayAdapter

    Votes: 0 0.0%

  • Total voters
    0

ivanlmj

Lurker
Hi everyone! First post here!

I want to make a clickable ListView that, when I click in one of the items, it will be started a new Activity, which will receive the item data from the ListView. e.g.: if I click on a item called Android from the ListView, it will be started a new activity with a TextView widget, showing the word Android, that came from the ArrayAdapter of the ListView?

Anyone here knows how to do this?

I know that I have to use Intents in order to start the activities, but how can I pass each item from the ArrayAdapter to a TextView widget from another Activity?

Here are the codes which I am using.

DisplayList.java
Code:
package com.redtjs.simplelistdisplay;

import android.os.Bundle;
import android.app.Activity;
import android.widget.ArrayAdapter;
import android.widget.ListView;


public class DisplayList extends Activity {

    String[] mobileArray = {"Android","IPhone","WindowsMobile","Blackberry"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_display_list);

        ArrayAdapter adapter = new ArrayAdapter<String>(this, R.layout.activity_row_layout, mobileArray);
        ListView listView = (ListView) findViewById(R.id.select_dialog_listview);
        listView.setAdapter(adapter);

    }

}
activity_display_list.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.redtjs.simplelistdisplay.DisplayList">

    <ListView
        android:id="@+id/select_dialog_listview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />

</LinearLayout>
activity_row_layout.xml
Code:
[/COLOR][/COLOR]
[COLOR=#00b300][COLOR=#000000]<?xml version="1.0" encoding="utf-8"?>

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/list_item"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dip"
    android:textSize="16sp"
    android:textStyle="bold" >
</TextView>


Here is the activity which I want to be instantiated when one of the items of the ListView is clicked.

DisplayRow.java
Code:
package com.redtjs.simplelistdisplay;

import android.app.Activity;
import android.os.Bundle;

public class DisplayRow extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_display_row);

    }

}

activity_display_row.xml

Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>



Thanks in advance!
 
Back
Top Bottom