0

Hi, guys, i made listactivity and i want to enter to other activities by clicking to list items. But there is a problem. This is my code:

public class Main extends ListActivity {

    String[] values = { "Samsung", "Sony Ericsson", "Iphone" };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);
        setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, values));
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        // TODO Auto-generated method stub
        super.onListItemClick(l, v, position, id);
        String myvalue= values[position];
        Intent openme= new Intent("com.myname.myapp." + myvalue);
        startActivity(openme);
    }

}

Edited by ziyaddinsadigov: editing

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by peter_budo
0

You can use that if you declare custom actions as for Android uses for example ACTION_VIEW, ACTION_EDIT, ACTION_MAIN. I do not recommend that since you just starting to learn. You better of with following constructor

new Intent(Context packageContext, Class<?> cls)

where you can get context by calling getApplicationContext() in application and provide name of the class you trying to invoke.

new Intent(getApplicationContext(), Samsung.class)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.