In this tutorial i will be demonstrating how to build simple android ListView. This article is about creating listview and launching new activity on selecting single list item.

Download Code

Below is screenshot of final output

Android List View

Let’s get start by creating a project in Eclipse IDE.

1. Create a new project by going to File ⇒ New Android Project. Fill all the details and name your activity as AndroidListViewActivity.
2. Once the project is created open your main activity java file (in this case AndroidListViewActivity.java) and extend the class from ListActivity.

public class AndroidListViewActivity extends ListActivity {

3. Now we need a string resources file to store all list item labels. So create an XML file under values folder and name it as list_data.xml and paste the following code.
( Right Click on res/values ⇒ New ⇒ Android XML File)

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="adobe_products">
    	<item>Adobe After Effects</item>
    	<item>Adobe Bridge</item>
    	<item>Adobe Dreamweaver</item>
    	<item>Adobe Edge</item>
    	<item>Adobe Fireworks</item>
    	<item>Adobe Flash</item>
        <item>Adobe Photoshop</item>
        <item>Adobe Premiere</item>
        <item>Adobe Reader</item>
        <item>Adobe Illustrator</item>
    </string-array>
</resources>

4. In ListView each list item will be an xml layout, so we can customize each list item. Create an XML file under res/layout folder and name it as list_item.xml and type the following code. This xml layout will be single list item row.
( Right Click on res/layout ⇒ New ⇒ Android XML File)


<?xml version="1.0" encoding="utf-8"?>
<!--  Single List Item Design -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
	android:id="@+id/label"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="10dip"
        android:textSize="16dip"
        android:textStyle="bold" >
</TextView>

5. Now open your main activity java file (AndroidListViewActivity.java) and type the following code. In the following code i am importing all xml resources data and storing them in an Array. On the next step i am binding array to ListAdapter.

package com.androidhive.androidlistview;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class AndroidListViewActivity extends ListActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        // storing string resources into Array
        String[] adobe_products = getResources().getStringArray(R.array.adobe_products);
        
        // Binding resources Array to ListAdapter
        this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, adobe_products));
        
    }
}

6. Now run your project you can see listview with list of array items. But on clicking single list item you can see no action. So we need to start new activity on selecting single list item.

Launching new Activity on selecting single list item

In my previous article i had explained how to switch between screens. Here i am going to show single list item details in new screen.

7. Now create new activity class under src folder. Right Click on src/package folder ⇒ New ⇒ Class and name it as SingleListItem. (SingleListItem.java)
8. Open your AndroidListViewActivity.java and modify the code to following. In the following code i am getting the selected list item string(product name) and sending it to new Activity.

package com.androidhive.androidlistview;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class AndroidListViewActivity extends ListActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        // storing string resources into Array
        String[] adobe_products = getResources().getStringArray(R.array.adobe_products);
        
        // Binding resources Array to ListAdapter
        this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, adobe_products));
        
        ListView lv = getListView();

        // listening to single list item on click
        lv.setOnItemClickListener(new OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view,
              int position, long id) {
        	  
        	  // selected item 
        	  String product = ((TextView) view).getText().toString();
        	  
        	  // Launching new Activity on selecting single List Item
        	  Intent i = new Intent(getApplicationContext(), SingleListItem.class);
        	  // sending data to new activity
        	  i.putExtra("product", product);
        	  startActivity(i);
        	
          }
        });
    }
}

Now in new activity we need to display the received from listview activity.

9. Create a new xml file under res/layout and name it as single_list_item_view.xml and type the following code. This XML file will be layout for SingleListItem.java

<?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:id="@+id/product_label"
  			android:layout_width="fill_parent"
  			android:layout_height="wrap_content"
  			android:textSize="25dip"
  			android:textStyle="bold"
  			android:padding="10dip"
  			android:textColor="#ffffff"/>    
</LinearLayout>

10. Now open your second activity file i.e SingleListItem.java and paste the following code.

package com.androidhive.androidlistview;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

public class SingleListItem extends Activity{
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.single_list_item_view);
        
        TextView txtProduct = (TextView) findViewById(R.id.product_label);
        
        Intent i = getIntent();
        // getting attached intent data
        String product = i.getStringExtra("product");
        // displaying selected product name
        txtProduct.setText(product);
        
	}
}

11. The final step is to add an entry of new activity name in AndroidManifest.xml file. Open you AndroidManifest.xml file and modify the code as below

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.androidhive.androidlistview"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".AndroidListViewActivity"
                  android:label="Android List View">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
        <activity android:name=".SingleListItem"
        			android:label="Single Item Selected"></activity>
    </application>
</manifest>

12. Finally run your project by right clicking on your project folder ⇒ Run As ⇒ 1 Android Application.

android listview single list item selected
Subscribe
Notify of
guest
308 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
trackback

[…] previous tutorial Android ListView Tutorial i explained how to create listview and updating with list data. Below i am implementing same […]

trackback

[…] previous tutorial Android ListView Tutorial i explained how to create listview and updating with list […]

trackback

[…] data in files. It is easy to parse and access data stored in JSON format. Previously i explained parsing XML and today i am going to discuess parsing JSON data with an […]

trackback

[…] is displayed using a listview. If you are not aware of listview go through this Android ListView Tutorial and get an idea of listview […]

trackback

[…] going further make sure that you covered Android XML Parsing Tutorial and Android ListView Tutorial […]

trackback

[…] classes and try to implement listview. If you are new to ListView i suggest you to go through Android ListView Tutorial […]

trackback

[…] my previous tutorial Android ListView Tutorial i explained how to create listview and updating with list data. Below i am implementing same […]

Ahmed IBRAHIM
Ahmed IBRAHIM
6 years ago

If you use a ListActivity/Fragment, the id for your ListView in your layout should be @android:id/list, so: In your whitelist_list.xml (whatever_activityname.xml) in your ListView change the id to android:id=”@android:id/list”

Ahmed IBRAHIM
Ahmed IBRAHIM
6 years ago

ListView listview = (ListView)findViewById(R.id.gridview);

listview.setAdapter(new MyAdapter(this));
/**to make the items clickable :
* In this case, is an Activity object that you must send to the Intent constructor. By doing this, you are telling your Intent object that you want to open the ActivityToCall activity when clicking on an item.

simply telling the intent that the currentActivity wants to open ActivityToCall activity
* */
listview.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView parent, View v, int position, long id)
{
Intent i = new Intent(CurentActivity.this, SecondActivity.class);

Toast.makeText(MainActivity.this, “you clicke”+position, Toast.LENGTH_SHORT).show();

startActivity(i);
}
});

Note that : the above code will case all the items in the list to open the same activity. In order to make every item open its own activity, you will have to create a different activity for every item and modify your code to be something like this:

Intent x = new Intent(MainActivity.this, SecondActivity.class);
Intent y = new Intent(MainActivity.this, SecondActivity.class);
Intent z = new Intent(MainActivity.this, SecondActivity.class);
//… and so on

if (position == 1){
startActivity(x);
}

elseif (position == 2){
startActivity(y);
}

elseif (position == 3){
startActivity(z);
}
//….. and so on.

Zael
Zael
6 years ago
Reply to  Ahmed IBRAHIM

Is there really no way to do this dynamically? (What if the list loses some items, gets others changed and gets some new ones from the users actions? ie. if/else is not sufficient.)

Ahmed IBRAHIM
Ahmed IBRAHIM
6 years ago
Reply to  Zael

As far as I know (1 year dusty knowledge), the answer is no. I am sorry but you will have to search around to see if this changed or not.

joubin
joubin
6 years ago

The app lunches okay, however, it crashes when I select one of the rows.

any ideas?
Here is how it happens: http://puu.sh/5ZZ3i.mp4
PS: I was not able to use the provided “AndroidManifest” instead im using the one that was auto generatord:

Apurva Agrawal
Apurva Agrawal
6 years ago

hey did you got d ansr bcs i am working on somthing same and i am facing the same problem pls help me..

apurva agrawal
apurva agrawal
6 years ago

hey I have similar problm wat mia have so pls help me out with this.

i am using tab host..and in the last tab, i want to display a simple lisIt view filled from array string in values,not database..so i did the first part of your tutorial which doesn’t do the work for me..and I don’t know why. the code is simple, and i don’t believe I made any mistakes. Do you maybe know if there is something special that I need to do because it’s tab host.

Thanks in advance

Syrine92
Syrine92
6 years ago

Hi

I have this Error (“R cannot be resolved to a variable”) in these instructions:

String[] adobe_products = getResources().getStringArray(R.array.adobe_products);

this.setListAdapter(new ArrayAdapter(this, R.layout.list_item, R.id.label, adobe_products));

Someone can help me please ?

Muhammad Shehzad Arshad Virk
Muhammad Shehzad Arshad Virk
6 years ago

hi i have java server i want to get data from TCP java and want to show in listview please suggest me a nice tutorial thanks

george
george
6 years ago

Hello. I need someone
to develop a simple app. will use java , php and sql. please reply to george.celsie@gmail.com
if you can help me. I will share the
credits :). Thanks

Ganesh Ghodake
Ganesh Ghodake
6 years ago
Reply to  george

Hello George. What kind of app you want to develop?

Muri
Muri
6 years ago
Reply to  Ganesh Ghodake

Hi Ganesh,
I also need help developing an app. I am new to java and I need to create a Listview which holds some amount of data. I did try create one for myself for it always crash. I think I am doing something wrong. So if you think you can help pls get in touch and we can talk more.

joaquindev
joaquindev
6 years ago

Great tutorial. I´ve created a github repo with the code. It may be useful to someone: https://github.com/joaquindev/android-listview.git Keep up the good work!

arpit
arpit
6 years ago

thanks for the tutorial,
but how can i show scroll-able text after selecting an item from above list.
For example:
if i select “Adobe Edge” then a new screen should show me “It is a product of Adobe Company developed by…, , etc, etc,…..”.
for doing this i can’t make new activity, because doing so will increase my .class files, and it is not a good programming practice in i have 50 items in a listview.
So please suggest me the way with code, thank you.

Jabs
Jabs
6 years ago

While we extending Activity class in our coding and another side we extends arrayadapter class than how we get selected item from Listview?

Surabhi Sugandha
Surabhi Sugandha
6 years ago

i have dyanamic arraylist…now how should i connect it to next activity

seçkin
seçkin
6 years ago

I try your problem, listview1 in listview2 [tree model] than listview2 next activty

Ben Tong
Ben Tong
6 years ago

If I want to add a subtext under the text, how should i add it?

RIdwan F.
RIdwan F.
6 years ago

hello ravi, this tutorial is work in my eclipse and i want to add a picture when i choose one of the list. can you tell me how it?
i’m sorry if my english so bad.

nana
nana
6 years ago

hello ravi, i would like to disable the whole selection of a list item and make buttons and links inside the list item clickable

Prashanth
Prashanth
6 years ago

Hi ravi, i have followed first step same as you mentioned but when i run the application i get a message the application has stopped unexpectedly

Ravi Tamada
6 years ago
Reply to  Prashanth

Please check your Logcat for errors

Prashanth
Prashanth
6 years ago
Reply to  Ravi Tamada

thanks for reply sorry i only made mistake i solved it i ve one more doubt the main activity bar is not showing in 2.3.3 gingerbird(API 10) but it’s showing in jellybean

Ravi Tamada
6 years ago
Reply to  Prashanth

If you mean to say Action Bar, ActionBar was introduced in API11. In older versions it won’t be displayed. If you want to display in older versions, here is the help
https://developer.android.com/training/basics/actionbar/setting-up.html

Prashanth
Prashanth
6 years ago
Reply to  Ravi Tamada

Thank u very much any tutorial i can get data’s from excel or notepad

Rishil Bhatt
Rishil Bhatt
6 years ago
Reply to  Prashanth

How do I display simple action bar (having a textview) on List view page??

Please help..

Dipak
Dipak
6 years ago

Hi , Thanks for awesome tutorial…..

Question:

At the bottom of your post you have attached two image files. In the first image file, “adobe fireworks” is highlighted.

Do you know how I can change the color for my lisview item onClick to orange and then when user takes their finger off screen it goes back to default black colour?

All the tutorial files online sugget writing code inside a drawable folder but I do not have a single drawable folder. I have 4 drawable folders i.e. drawable mdpi, drawable ldpi etc

My code in Activity.java file looks like this:

list.setOnItemClickListener(new OnItemClickListener(){

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

}

});

Thank you for your help

Ravi Tamada
6 years ago
Reply to  Dipak

You can create a new folder with the name ‘drawable’ and add the xml files. Use the gradient_bg.xml, gradient_bg_hover.xml, list_selector.xml files from below tutorial.
http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/

Dipak
Dipak
6 years ago
Reply to  Ravi Tamada

Thank you very much….Can I please double check with you that the “drawable” folder most online tutorials speak about creating is to created under the “res” directory where the other drawable folders are?? pls kindly clarify for me….

Thank you for the link to tutorial. My mp3 files are stores on SQL server database where I have stored the web links to the mp3.

Thanks alot, i appreciate your time and am grateful for your response.

Ravi Tamada
6 years ago
Reply to  Dipak

Yeah, drawable folder used to create under res folder when a new project is created when using older build tools(May be you are reading the articles written in those days). Now in recent build tools this folder is not creating by default. We have to create it manually whenever required.

Spike
Spike
6 years ago

Very useful tutorial.
How do I alter the code to add details of each product, for display on the second screen?

Ravi Tamada
6 years ago
Reply to  Spike

It is already there in the tutorial in 8th point.

Spike
Spike
6 years ago
Reply to  Ravi Tamada

Stage 8 shows how to put 1 piece of info on the second screen, but I was wondering about putting a review, and maybe a picture, as well as the title.

Ravi Tamada
6 years ago
Reply to  Spike

Then you can create a model class which contains object of your listview item. Ex: Movie class with title, picture. Implement this model class from Serializable.

When you launch the intent pass this model class in putExtra method.

Check below link.
http://stackoverflow.com/questions/2736389/how-to-pass-object-from-one-activity-to-another-in-android

Aurino Jr
Aurino Jr
6 years ago

Great tutorial

MuscleAche
MuscleAche
6 years ago

I have a very long list, how can i make it so that the list will only update when i scrolled till the end?

Eric Balcon
Eric Balcon
6 years ago

first part doesn’t work for me while I try binding resources array to listAdapter: the setListAdapter causes an error

alvin
alvin
6 years ago

I want have the list only appear when i type something in the search box,how would you do this?

alvin
alvin
6 years ago

opps!!sorryy my question was for another page

Domon Lee
6 years ago

Thanks a lot.this is very useful!

Nishant Jaisinghani
Nishant Jaisinghani
6 years ago

Hi Ravi, Thank you for your tutorials they are really helpfull….i have created a basic listview app….all coding is done….but when i try to run the app its showing error ” app has stopped working”.

thank you

Abdul ReHman Naseem
6 years ago

Dear Sir, Thank you Great help.
Ravi In addition to this tutorial I want to ask If I want to Write something or add some text or images in Adobe Fireworks Page/new screen. How can I do that? Thank you

Rishil Bhatt
Rishil Bhatt
6 years ago

:disqus : Thank you for the tutorial….I would like to add the background image to the listview.

I tried with lv.setBackgroundColor(R.drawable.sample);
It’s not working.
Could you help me out ?

And Thanks again for the great work….Cheers

Nitesh
Nitesh
6 years ago
Reply to  Rishil Bhatt

in your xml write
android:background=”@drawable/your-image”

Ajlinda Cerdaku
Ajlinda Cerdaku
6 years ago

Thank you very much for the Tutorial! I would like to add a stream, when i click on the item…
can u help? Thank you

palsu
palsu
5 years ago

when i click the item, in single_list_item.class not display the item, only blank layout
helpv:)

khalil b
khalil b
5 years ago
Reply to  palsu

It works Perfectly for me, Believe me If you follow this tuto step by step you can get it, may be Mr ravi tamada work with Holo dark, change the TextColor to Black like #000000 on single_list_item.xml and its done 😉

Guest
Guest
5 years ago

God Bless you Mr.Ravi tamada you and your family and all person like you,

Ravi Tamada
5 years ago
Reply to  Guest

Thank You 🙂

Arbaaz
Arbaaz
4 years ago
Reply to  Ravi Tamada

Hello, it will be great help if you can do tutorial on list view populating data from sqlite database thanks.

Ravi Tamada
4 years ago
Reply to  Arbaaz
Arbaaz
Arbaaz
4 years ago
Reply to  Ravi Tamada

And what about Adapter which adapter i should use to set on listview because i don’t think so arrayadapter will work with database.

Ravi Tamada
4 years ago
Reply to  Arbaaz

You need to use a custom adapter, fetch the data from database and attach to it.

Also use RecyclerView instead of ListView.
http://www.androidhive.info/2016/01/android-working-with-recycler-view/

Arbaaz
Arbaaz
4 years ago
Reply to  Ravi Tamada

Thank you buddy 🙂 and your tutorials are awesome great work keep it up.

Ravi Tamada
4 years ago
Reply to  Arbaaz

Cheers!

ali
ali
5 years ago

hi

i have a big problem

i use this site to make a search engine !

but when activity start , occur Force Close.

error log is :

12-03 16:07:50.879: E/AndroidRuntime(4330): FATAL EXCEPTION: main
12-03 16:07:50.879: E/AndroidRuntime(4330): Process: ir.korang.powerelectron.AndroidTrainingReference, PID: 4330
12-03 16:07:50.879: E/AndroidRuntime(4330): java.lang.RuntimeException: Unable to start activity ComponentInfo{ir.korang.powerelectron.AndroidTrainingReference/ir.korang.powerelectron.AndroidTrainingReference.Contact}: java.lang.NullPointerException
12-03 16:07:50.879: E/AndroidRuntime(4330): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
12-03 16:07:50.879: E/AndroidRuntime(4330): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
12-03 16:07:50.879: E/AndroidRuntime(4330): at android.app.ActivityThread.access$800(ActivityThread.java:135)
12-03 16:07:50.879: E/AndroidRuntime(4330): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
12-03 16:07:50.879: E/AndroidRuntime(4330): at android.os.Handler.dispatchMessage(Handler.java:102)
12-03 16:07:50.879: E/AndroidRuntime(4330): at android.os.Looper.loop(Looper.java:136)
12-03 16:07:50.879: E/AndroidRuntime(4330): at android.app.ActivityThread.main(ActivityThread.java:5001)
12-03 16:07:50.879: E/AndroidRuntime(4330): at java.lang.reflect.Method.invokeNative(Native Method)
12-03 16:07:50.879: E/AndroidRuntime(4330): at java.lang.reflect.Method.invoke(Method.java:515)
12-03 16:07:50.879: E/AndroidRuntime(4330): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
12-03 16:07:50.879: E/AndroidRuntime(4330): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
12-03 16:07:50.879: E/AndroidRuntime(4330): at dalvik.system.NativeStart.main(Native Method)
12-03 16:07:50.879: E/AndroidRuntime(4330): Caused by: java.lang.NullPointerException
12-03 16:07:50.879: E/AndroidRuntime(4330): at ir.korang.powerelectron.AndroidTrainingReference.Contact.onCreate(Contact.java:52)
12-03 16:07:50.879: E/AndroidRuntime(4330): at android.app.Activity.performCreate(Activity.java:5231)
12-03 16:07:50.879: E/AndroidRuntime(4330): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
12-03 16:07:50.879: E/AndroidRuntime(4330): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
12-03 16:07:50.879: E/AndroidRuntime(4330): … 11 more
12-03 16:07:58.475: I/Process(4330): Sending signal. PID: 4330 SIG: 9
12-03 16:18:16.691: D/dalvikvm(4442): GC_FOR_ALLOC freed 45K, 3% free 3543K/3652K, paused 4ms, total 5ms
12-03 16:18:16.691: I/dalvikvm-heap(4442): Grow heap (frag case) to 9.010MB for 5760012-byte allocation
12-03 16:18:16.723: D/dalvikvm(4442): GC_FOR_ALLOC freed <1K, 2% free 9168K/9280K, paused 25ms, total 25ms
12-03 16:18:16.947: D/(4442): HostConnection::get() New Host Connection established 0xb7f36090, tid 4442
12-03 16:18:20.867: D/dalvikvm(4442): GC_FOR_ALLOC freed 5K, 1% free 9201K/9280K, paused 3ms, total 4ms
12-03 16:18:20.875: I/dalvikvm-heap(4442): Grow heap (frag case) to 12.671MB for 3804812-byte allocation
12-03 16:18:20.883: D/dalvikvm(4442): GC_FOR_ALLOC freed <1K, 1% free 12916K/12996K, paused 8ms, total 8ms
12-03 16:18:21.011: D/dalvikvm(4442): GC_FOR_ALLOC freed 1K, 1% free 15952K/16036K, paused 3ms, total 3ms
12-03 16:18:29.923: D/AndroidRuntime(4442): Shutting down VM
12-03 16:18:29.923: W/dalvikvm(4442): threadid=1: thread exiting with uncaught exception (group=0xa4caeb20)
12-03 16:18:29.931: E/AndroidRuntime(4442): FATAL EXCEPTION: main
12-03 16:18:29.931: E/AndroidRuntime(4442): Process: ir.korang.powerelectron.AndroidTrainingReference, PID: 4442
12-03 16:18:29.931: E/AndroidRuntime(4442): java.lang.RuntimeException: Unable to start activity ComponentInfo{ir.korang.powerelectron.AndroidTrainingReference/ir.korang.powerelectron.AndroidTrainingReference.Search}: java.lang.NullPointerException
12-03 16:18:29.931: E/AndroidRuntime(4442): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
12-03 16:18:29.931: E/AndroidRuntime(4442): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
12-03 16:18:29.931: E/AndroidRuntime(4442): at android.app.ActivityThread.access$800(ActivityThread.java:135)
12-03 16:18:29.931: E/AndroidRuntime(4442): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
12-03 16:18:29.931: E/AndroidRuntime(4442): at android.os.Handler.dispatchMessage(Handler.java:102)
12-03 16:18:29.931: E/AndroidRuntime(4442): at android.os.Looper.loop(Looper.java:136)
12-03 16:18:29.931: E/AndroidRuntime(4442): at android.app.ActivityThread.main(ActivityThread.java:5001)
12-03 16:18:29.931: E/AndroidRuntime(4442): at java.lang.reflect.Method.invokeNative(Native Method)
12-03 16:18:29.931: E/AndroidRuntime(4442): at java.lang.reflect.Method.invoke(Method.java:515)
12-03 16:18:29.931: E/AndroidRuntime(4442): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
12-03 16:18:29.931: E/AndroidRuntime(4442): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
12-03 16:18:29.931: E/AndroidRuntime(4442): at dalvik.system.NativeStart.main(Native Method)
12-03 16:18:29.931: E/AndroidRuntime(4442): Caused by: java.lang.NullPointerException
12-03 16:18:29.931: E/AndroidRuntime(4442): at ir.korang.powerelectron.AndroidTrainingReference.Search.onCreate(Search.java:34)
12-03 16:18:29.931: E/AndroidRuntime(4442): at android.app.Activity.performCreate(Activity.java:5231)
12-03 16:18:29.931: E/AndroidRuntime(4442): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
12-03 16:18:29.931: E/AndroidRuntime(4442): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
12-03 16:18:29.931: E/AndroidRuntime(4442): … 11 more

please help me.

kunal kumar
kunal kumar
5 years ago
Reply to  ali

TextView tv=(TextView)findViewById(R.id.label);

define id of the textview
and then
tv.getText().toString();
like this

public void onItemClick(AdapterView parent, View view, int position,
long id) {
// TODO Auto-generated method stub
@SuppressWarnings(“unused”)
//TextView tv;
TextView tv=(TextView)findViewById(R.id.label);
String product=tv.getText().toString();
String pos=””+position;

Intent i=new Intent(getApplicationContext(),SingleListItem.class);
i.putExtra(“product”,product);
i.putExtra(“position”, pos);
startActivity(i);
}

Nam
Nam
5 years ago

Thank you so much for the Tutorial, Mr.Ravi. It’s really helpful !

jabeelee
jabeelee
5 years ago

how to put search engine in your code?

Mohammad Janbein
Mohammad Janbein
5 years ago

Thank u ,but how to make every item open a text view.

mani
mani
5 years ago

i want play video list pls gie me a code

mani
mani
5 years ago

how can play number of video from my hard disk

Kira
Kira
5 years ago

I can’t download your examples 🙁

Kira
Kira
5 years ago
Reply to  Kira

works now 🙂

Sam
Sam
5 years ago

Hello sir,Thx for this great tutorial.I’m a beginner in android development.
I have one que. sir,when i click on any item its showing only item name.What should i do if i want to show some text,paragraphs and images in specific item like Adobe After Effects.

namo
namo
5 years ago

hi rav. very nice tutorial. But please how do i make each item e.g adobe to launch a new activitys very very i when clicked? please it is very very urgent. thanks a lot sir.

stelios
stelios
5 years ago

Hi Ravi. This is a amazing turtorial. Well done. Its very helpfull. I have one question. After copy paste and test this project its missing from my device the text on top “Android List view”. Why is that happening? Is something missing from the codes?

Thank you very much

qudsia
qudsia
5 years ago

any one can help me please. i want to make list items clickable .but it doesn’t work.

विनय सोमवंशी
विनय सोमवंशी
5 years ago

how to create a seperate screen for every list item…..???

PrakashK Gowin
PrakashK Gowin
4 years ago

Hi Vinay, Create a separate Activity or Fragment for loading each of your lists

M Hussain Afridi
5 years ago

Our Dear sir , same exact article we need But data will be from json array or mysql database

Aneudy Amparo
Aneudy Amparo
5 years ago
308
0
Would love your thoughts, please comment.x
()
x