Start an activity from a listview

前端 未结 2 1820
孤独总比滥情好
孤独总比滥情好 2021-01-16 19:25

Hi I have a listview and, I am trying to start an activity from the listview by startActivity(class.java);

public class ll2 extends Activity {

         


        
相关标签:
2条回答
  • 2021-01-16 20:01

    I struggled with this all day and thought id post it everywhere i could.

    I got the a little easier answer. Basically i turned it into a string so i could just type out what i wanted where.

    protected void onListItemClick(ListView l, View v, int position, long id) {
        String item = (String) getListAdapter().getItem(position);
        if (item.equals("Economy"))
            {
    
        Intent intent = new Intent(packages.this, economy.class);
            startActivity(intent);
    }
        else if (item.equals("Basic"))
        {
    
    Intent intent = new Intent(packages.this, basic.class);
        startActivity(intent);
    }
        else if (item.equals("Professional"))
        {
    
    Intent intent = new Intent(packages.this, professional.class);
        startActivity(intent);
    }
    }
    
    0 讨论(0)
  • 2021-01-16 20:04

    MyList()[position] should be myList[position].
    Next you can not start an activity like this startActivity(Bradford.java);. For starting a new activity you need to create and intent and then set the Activity class. Then you can call startActivity with that intent.

    Intent intent = new Intent();
    intent.setClass(this, Bradford.class);
    startActivity(intent);
    And you need to add Bradford activity to your manifest as well.

    0 讨论(0)
提交回复
热议问题