Home
› Uncategorized
Example to implement ListView NOT extends ListActivity:
Create /res/layout/row.xml to define the layout of rows in ListView.
Modify the layout to add a ListView.
Create /res/layout/row.xml to define the layout of rows in ListView.
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="25sp" />
Modify the layout to add a ListView.
<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"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" tools:context=".MainActivity" /> <ListView android:id="@+id/mylist" android:layout_width="match_parent" android:layout_height="wrap_content"/> </LinearLayout>
package com.example.androidlistview; import android.os.Bundle; import android.app.Activity; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.Toast; public class MainActivity extends Activity { String[] month ={ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ListView myListView = (ListView)findViewById(R.id.mylist); ListAdapter myListAdapter = new ArrayAdapter<String>( getApplicationContext(), R.layout.row, month); myListView.setAdapter(myListAdapter); myListView.setOnItemClickListener(new OnItemClickListener(){ @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(getApplicationContext(), parent.getItemAtPosition(position).toString(), Toast.LENGTH_LONG).show(); } }); } }
-- Delivered by Feed43 service
Related Posts
There is no other posts in this category.Popular
-
[Android] The Dark Knight Rises v1.1.1 APK by GameloftThe Dark Knight Rises is one of the hottest games just released by Gameloft in July 2012 on Androi…
-
The Avengers – Iron Man Mark VII 1.1 APKThe Avengers – Iron Man Mark VII 1.1 APK Suit up and Blast off in the First-Ever Fully-Interactive …
-
Angry Birds Space v1.0.1 for AndroidAngry Birds Space v1.0.1 for Android The #1 mobile game of all time blasts off into space! All new …
-
Ripple Lock v1.6Ripple Lock v1.6 Requirements: for Android version 2.1 and higher Overview: Is still envy of the br…
-
How To: Copy And Paste In Android Mobile'>The copy, cut, paste and select the features Android has many nuances. In this how-to, we will foc…
-
Facebook for Android v1.8.3Facebook for Android v1.8.3 Requires Android:1.5 and up Share status updates from your home screen,…
-
DROID RAZR - Motorola SmartphonesDROID RAZR DROID RAZR brings the best the Motorola has to offer in smartphones. They’ve really thr…
Post a Comment
Post a Comment