Home > Android > Android Listview Example

Android Listview Example

listview onclick array adapter source code download

Android For Freshers

Android Listview Example

Android Listview Example

Java Code(ListViewAct)

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class ListViewAct extends Activity {
ListView lv1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_view);
lv1=(ListView)findViewById(R.id.lv1);
final String items[]={“c”,”java”,”c++”,”android”};

ArrayAdapter aa=new ArrayAdapter(this,android.R.layout.simple_dropdown_item_1line,items);
lv1.setAdapter(aa);
lv1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

Toast.makeText(ListViewAct.this, items[position], Toast.LENGTH_SHORT).show();
}
});
}

}


Layout XML Code(activity_list_view)

<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:orientation=”vertical”
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.andro.tech.androidproject.ListViewAct”>

<TextView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:textSize=”@dimen/textsize”
android:textStyle=”bold”
android:layout_gravity=”center”
android:text=”@string/listviewtext”
android:layout_marginBottom=”10dp” />

<ListView
android:layout_width=”match_parent”
android:layout_height=”300dp”
android:id=”@+id/lv1″
android:layout_marginBottom=”50dp”>
</ListView>

<Button
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”@string/sourcecode”
android:background=”@color/bgcolor”
android:textStyle=”bold”
android:textColor=”@color/text”
android:onClick=”view1″/>

</LinearLayout>

Output : 

Android Listview Example    Android Listview Example

ListView onClick array adapter source code download 

Download List View Source Code

For More Android Programs –Click Here

 

Follow Us – Never Miss Update

Fb/PageTwitterGoogle+InstagramPinterest 

 

Related Search

Android listview adapter source code download, Android list view source code download, android source code listview adapter download, android listview array adapter source download, listview array adapter snippet code download, array adapter listview source code download, listview onclick array adapter source code download

Is This Content Useful For You?