Reputation: 161
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
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
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
Reputation: 128448
Wrong:
startActivity(new Intent(Listview));
Correct way to start Activity:
startActivity(new Intent(CurrentClassName.this, DestinationClassName.class));
To understand more about Intent, check and read below articles:
Upvotes: 3