Akaash Garg Akaash Garg - 1 month ago 7
Android Question

How to jump from ListView to next Activity

I am using these codes to jump from listview to selected class

public class mainmenu extends Activity{


private ListView lv1 ;
private ArrayAdapter listAdapter ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView (R.layout.mainmenu);

lv1 = (ListView) findViewById(R.id.options);


String[] lv_arr= new String [] { "Book a Classified Ad" , "Book a Classified display Ad" , "Book a display Ad" , "Page Position Availability" , "MIS" , "Market Share" , "Approval" , "Upload Material", "Exit" };
ArrayList Options = new ArrayList();

Options.addAll(Arrays.asList(lv_arr));
listAdapter = new ArrayAdapter(this, R.layout.simplerow, Options);

lv1.setAdapter( listAdapter );

lv1.setTextFilterEnabled(true);
lv1.setClickable(true);

lv1.setOnItemClickListener(new ListView.OnItemClickListener() {
public void onItemClick( AdapterView<?> a, View v, int position, long id) {

position = a.getSelectedItemPosition();
a.setSelection(position);
int pos1 = position;



if (pos1 == 0) {

Intent intent = getIntent();
intent = new Intent(mainmenu.this,classifiedAd.class);
startActivity(intent);

}


else if (pos1 == 1 || pos1 == 2) {
Intent intent1 = new Intent(mainmenu.this, displayAd.class);
startActivity(intent1);
}


else if (pos1 == 3) {
Intent intent3 = new Intent(mainmenu.this, spaceAvail.class);
startActivity(intent3);
}
else if (pos1 == 4) {
Intent intent4 = new Intent(mainmenu.this, mis.class);
startActivity(intent4);
}
else if (pos1 == 5) {
Intent intent5 = new Intent(mainmenu.this, mark.class);
startActivity(intent5);
}
else if (pos1 == 6) {
Intent intent6 = new Intent(mainmenu.this, approval.class);
startActivity(intent6);
}
else if (pos1 == 7) {
Intent intent7 = new Intent(mainmenu.this, uploadMat.class);
startActivity(intent7);
}
else if (pos1 == 8) {
finish();
}
}

});


}


}

where is the problem ?

Answer

instead of position i have to get the Label

Object GetLabel = lv1.getItemAtPosition(position);
if (GetLabel.toString().equals("Book a Classified Ad")) {

                     Intent intent = new Intent(mainmenu.this, classifiedAd.class);
                     startActivity(intent);                  
                    }
Comments