Structure Query Language, C programming, Java, Servlet, Jsp, Unix

Thursday, 18 October 2012

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.

Pro5Activity
package ps.pro5;
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 Pro5Activity extends Activity implements OnClickListener {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 EditText editnum;
 Button btshow;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        editnum=(EditText) findViewById(R.id.editTextNumber);
        btshow=(Button) findViewById(R.id.buttonshow);
        
        btshow.setOnClickListener(this);
    
    }
 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
  if(v.getId()==btshow.getId())
  {
   Intent myintent=new Intent(this,listActivity.class);
   myintent.putExtra("num", Integer.parseInt(editnum.getText().toString()));
   this.startActivity(myintent);
  }
 }
}
listActivity.java
package ps.pro5;

import android.app.Activity;
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.Toast;

public class listActivity extends Activity implements  OnItemClickListener {
    /**
     *  www.master-gtu.blogspot.com
     *  pankaj sharma(8460479175),
     *  chavda vijay(8460420769) 
     */
 ListView lv;
 String items[];
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listlayout);
        
        lv=(ListView) findViewById(R.id.listViewItems);
        int num=getIntent().getIntExtra("num", 0);
        items=new String[num];
        for(int i=0;i<num;i++)
        {
         items[i]="item "+(i+1);
        }
        ArrayAdapter<String> arr=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,items);
        lv.setAdapter(arr);
       
        lv.setOnItemClickListener(this);
    }
 @Override
 public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
  // TODO Auto-generated method stub
  Toast.makeText(this,items[pos] + " selected", Toast.LENGTH_SHORT).show();
 }
}

5 comments: