可点击的自定义数组列表

时间:2018-11-06 19:36:23

标签: android android-studio android-intent

我如何使此自定义数组列表可点击以转到其他活动,因为我尝试了这些意图但不起作用

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ArrayList<Names> namesArrayList = new ArrayList<Names>();

        namesArrayList.add(new Names(R.drawable.call_centre, "Call Centre"));
        namesArrayList.add(new Names(R.drawable.soco_academy_icon, "Academy"));

        NamesAdapter  NamesListAdapter = new NamesAdapter(this, namesArrayList);

        ListView list = (ListView) findViewById(R.id.List_View);

        list.setAdapter(NamesListAdapter);

        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {



            }
        });
    }
}

1 个答案:

答案 0 :(得分:0)

onItemClick()中,您可以通过执行以下操作确定单击了哪个项目:

Name selectedName = NamesListAdapter.getItem(position);

然后,您可以执行此操作。