first xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="60dp"
ads:adUnitId="id"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
<!-- List View -->
<ListView
android:id="@+id/list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
2xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- Single ListItem -->
<!-- Product Name -->
<TextView
android:id="@+id/product_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/ylistbg"
android:padding="10dip"
android:textSize="16dip"
android:textStyle="bold" />
</LinearLayout>
jav
public class ListviewOnclickExample extends Activity |
02 | { |
03 | private ListView lv1; |
04 | private String lv_arr[]={ "Android" , "iPhone" , "BlackBerry" , "AndroidPeople" , "J2ME" , "Listview" , "ArrayAdapter" , "ListItem" , "Us" , "UK" , "India" }; |
05 | @Override |
06 | public void onCreate(Bundle icicle) |
07 | { |
08 | super .onCreate(icicle); |
09 | setContentView(R.layout.main); |
10 | lv1=(ListView)findViewById(R.id.ListView01); |
11 | lv1.setAdapter( new ArrayAdapter this ,android.R.layout.slist_item, R.id.product_name, listdisplay)); |
12 |
13 | lv1.setOnItemClickListener( new OnItemClickListener() { |
14 | @Override |
15 | public void onItemClick(AdapterView a, View v, int position, long id) { |
16 | | TextView textView = (TextView)arg1.findViewById(R.id.product_name); | textt = textView.getText().toString(); |
21 | } |
22 | }); |
23 | } |
24 | } |
No comments:
Post a Comment