简体   繁体   中英

How to bind costum id in android list view?

I'm new in android/java development.

I want to bind custom Id in ListView.

In pList i have project name, in pListId i have project id's:)

        List<String> pList = new ArrayList<String>();
    List<String> pListId = new ArrayList<String>();

    for(int i =0; i<len;i++){
        Log.w("s",project.getProjectName(i));
        //projects[i]=project.getProjectName(i);
        pList.add(project.getProjectName(i));
        pListId.add(project.getProjectId(i));
    }

    setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, plist));

When i click on name i want to get the id and i can open new Activity.

Thanks.

Override onListItemClick like in

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);

    String mainString = main[position];
    Class mainClass = null;

    try {
        mainClass = Class.forName("com.packagename." + mainString);
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    Intent mainIntent = new Intent(mainMenu.this, mainClass);
    startActivity(mainIntent);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM