Member Avatar for ziyaddinsadigov

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);
    }

}

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)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.