subburaj
subburaj

Reputation: 161

LIst view in Android

In my sample program in 1stscreen i have one input field,based on this input i have to show a list view(which is another activity)how can i implement that.I am new to android.Here is my code.

This is after clicking button:

if(text1.getText().toString().equals("subbu"))
            { 
                startActivity(new Intent(Listview));
//              Toast.makeText(Sampleprojectsubbu1Activity.this,"Name:"+text1.getText().toString(), Toast.LENGTH_LONG).show();              
            }

This is the list to be shown:Just for sample i have given some unwanted array.

public class Listview extends ListActivity 
{
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES));

    }
    static final String[] COUNTRIES = new String[] 
            {
                   "XXXXX","YYYYYY"

            };

}

Upvotes: 1

Views: 119

Answers (3)

nikki
nikki

Reputation: 3228

You have to implement like this by replacing your code line

startActivity(new Intent(Listview)); with

startActivity(MainActivty.this,ListView.class);

and it is very important to add this new activity in manifest.

Upvotes: 1

GAMA
GAMA

Reputation: 5996

In main activity:

Intent myIntent = new Intent(this, ListView.class);
myIntent.putExtra("variableName", variableValue);
this.startActivity(myIntent);

and in ListView class:

Bundle extras = getIntent().getExtras();
if (extras != null) {
String varName = extras.getString("variableName");//Datatype can be any
}

Upvotes: 1

Paresh Mayani
Paresh Mayani

Reputation: 128448

Wrong:

 startActivity(new Intent(Listview));

Correct way to start Activity:

startActivity(new Intent(CurrentClassName.this, DestinationClassName.class));

Update:

To understand more about Intent, check and read below articles:

  1. Android Intents
  2. Intents and Intent Filters

Upvotes: 3

Related Questions