I am trying open an other activity on click of the list item of list view, and display the data of the clicked list item onto the new activity . But I am able to get the data of the list item onclick but when i'm starting new activity using startAcitvity(intent) method , then only a blank activity is opening , and on debugging i'm getting the info that startActivity() is undefined . Please help me to resolve this issue . My code is here:
public class MainActivity extends AppCompatActivity {
ListView lvDetail;
Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lvDetail = (ListView) findViewById(R.id.list);
new ProgressTask(MainActivity.this).execute();
lvDetail.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
try {
intent = new Intent(MainActivity.this, DataDisplayer.class);
Employee e = (Employee) parent.getItemAtPosition(position);
ArrayList<String> el = new ArrayList<String>();
el.add(String.valueOf(e.getId()));
el.add(e.getName());
el.add(String.valueOf(e.getAge()));
el.add(String.valueOf(e.getSalary()));
Bundle bundle = new Bundle();
bundle.putStringArrayList("emp", el);
intent.putExtras(bundle);
//intent.putStringArrayListExtra("emp", el);
startActivityForResult(intent, 187);
} catch (Exception er) {
er.printStackTrace();
}
}
});