postheadericon listview in android


Create an application that will pass some number to the next screen ,and on the next screen that number of items should be display in the list.


File Name : E5Activity.java


 package bsr.exa;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class E5Activity extends Activity {
/** @author Bipin S Rupadiya , www.BipinRupadiya.com
     *
     *   5) Create an application that will pass some number to the next screen ,
     *    and on the next screen that number of items should be display in the list.
     **/
EditText txtNum;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
     
        final Intent i= new Intent(this,ShowList.class);
     
        txtNum =(EditText)findViewById(R.id.txtNum);
        final Button btnView=(Button)findViewById(R.id.btnView);
        btnView.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
i.putExtra("Num", txtNum.getText().toString());
startActivity(i);
}
});
     
    }
}

File Name : ShowList.java


package bsr.exa;
import java.util.ArrayList;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
/** @author Bipin S Rupadiya , www.BipinRupadiya.blogspot.in
 *
 *   5) Create an application that will pass some number to the next screen ,
 *    and on the next screen that number of items should be display in the list.
 **/
public class ShowList extends ListActivity
{
    ArrayList<String> arr=new ArrayList<String>();
ArrayAdapter<String> a;  
int i,n;
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        a = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 ,arr);    
     
        setListAdapter(a);
        n=Integer.parseInt(getIntent().getStringExtra("Num"));
        for(i=0; i<n ; i++)
        {
        arr.add("Item : "+i);
        }
    }
}

AndroidManifest.xml


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="bsr.exa"
      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=".E5Activity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="ShowList"></activity>

    </application>
</manifest>

Follow by Email

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.